Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaced User Model (Spree)... #79

Closed
interhive opened this issue Feb 3, 2015 · 7 comments
Closed

Namespaced User Model (Spree)... #79

interhive opened this issue Feb 3, 2015 · 7 comments
Assignees

Comments

@interhive
Copy link

I'm trying to integrate StoryTime into an existing Spree e-commerce app and am getting the following errors:

When visiting http://myapp/storytime:

NoMethodError (undefined method `authenticate_spree::user!' for #<Storytime::Dashboard::PostsController:0x007f34f891cb78>):
  storytime (1.1.1) app/controllers/storytime/application_controller.rb:33:in `authenticate_user!'

When visiting http://myapp/:

NoMethodError (undefined method `current_spree::user' for #<Storytime::ApplicationController:0x007f34f91b8728>):
  storytime (1.1.1) app/controllers/storytime/application_controller.rb:37:in `current_user'
  storytime (1.1.1) app/controllers/storytime/application_controller.rb:20:in `setup'

I believe this has to do with the fact that I'm using a namespaced user model (Spree::User) in the config/initializers/storytime.rb file:

Storytime.configure do |config|
  # Name of the model you're using for Storytime users.
  config.user_class = 'Spree::User'
end

Any ideas on how to fix this?

Thanks so much!

@bcroesch
Copy link
Contributor

bcroesch commented Feb 3, 2015

Sounds like our user helpers are choking on the module part of your user class. Are you using spree_auth_devise? If so, we can probably make a quick change tomorrow to make it use current_spree_user instead of current_spree::user.

@interhive
Copy link
Author

Yes, I'm using the spree_auth_devise gem for Devise.

I appreciate the help. Thanks again!

@bcroesch
Copy link
Contributor

bcroesch commented Feb 3, 2015

Good deal. We'll take a closer look tmrw, but I think it should be a relatively easy fix. Thanks for using Storytime!

@interhive
Copy link
Author

Hope to be using it real soon! 👍

@eanlain eanlain self-assigned this Feb 4, 2015
eanlain pushed a commit that referenced this issue Feb 4, 2015
@eanlain eanlain closed this as completed in 950e11d Feb 4, 2015
eanlain pushed a commit that referenced this issue Feb 4, 2015
@eanlain
Copy link
Contributor

eanlain commented Feb 4, 2015

I pushed out Storytime v1.2.0 which should fix the issues that you experienced when trying to get this running with Spree. I ended up creating a Spree app using both the spree and spree_auth_devise gems to test this out and everything seemed to work with the below settings (using Storytime v1.2.0).

A couple of changes are needed on your end:

  1. Regenerate the Storytime initializer - just re-run rails generate storytime:install , but make sure you check your routes file to see that the Storytime engine mount isn't listed twice.
  2. In the Storytime initializer, uncomment the config.login_path, config.logout_path, and config.logout_method lines and change to the following (assuming you're using the default Spree routes):

config/initializers/storytime.rb

# Path used to sign users in. 
config.login_path = '/user/spree_user/sign_in'

# Path used to log users out. 
config.logout_path = '/user/spree_user/logout'

# Method used for Storytime user logout path.
config.logout_method = :get

Also, I had to create a decorator to add storytime_user to the Spree::User class, since the model is part of the Spree gem.

app/decorators/models/spree/user_decorator.rb

Spree::User.class_eval do
  storytime_user
end

Let us know if you run into any issues or if this works out for you.

@interhive
Copy link
Author

Thanks, I've been playing with the updated code without too many issues. I had already setup the user_decorator yesterday and had the same code as you, so that's good.

Did you mount Spree under a different path or did you keep it mounting at: '/' as well?

I was thinking I may have to place Spree within a /shop namespace to make them play well together.

My routes.rb file:

Rails.application.routes.draw do
  mount Spree::Core::Engine,  at: '/shop/'
  mount Storytime::Engine,    at: '/'

I'm seeing an issue with Spree not keeping its links under the /shop namespace. It looks like there's a call to /cart_link that's called every time a Spree page is displayed. This should obviously be a call to /shop/cart_link instead. With the error, it's being passed on to Storytime and it's failing on a RecordNotFound error.

Will post the bug report with the Spree team. Thanks so much for making the changes to make Storytime play well with Spree!

@eanlain
Copy link
Contributor

eanlain commented Feb 4, 2015

I tried changing my routes.rb file to match yours and I see the same behavior, where Spree tries to hit "/cart_link" regardless of where the engine is mounted. It looks like that's an ajax call that gets sent for every Spree page you go to.

Glad the changes worked for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants