Undefined method 'model' for User
I made authentication in my Rails 3 app fallowed by Tony's tutorial and this second tutorial开发者_运维技巧.
But I get
undefined method 'model' for User
It's just copy/paste from tutorial, and I think that is problem someone in my app architecture :)
I get error when I try access to /users/new
- mysql dump
- whole app
- error trace
I am unable to reproduce the problem that you are having on my local be here is my best guess: The only reason @user exists on in your view is because you are calling load_and_authorize_resource in your controller which is a CanCan method that creates the @user object. This might be the source of your problem so you could try using authorize_resource and then explicitly creating @user in your new method.
Here are a couple of things that I noticed:
- The standard create user path for devise is /users/sign_up but you are using /users/new which points to your custom users controller that is not part of devise, this will be very problematic when using devise modules like confirmable because it won't create the confirmation tokens or send out the emails.
- You have created a custom controller for registrations but you haven't told devise about it. You will need to do something like
devise_for :users, :controllers => { :registrations => "users/registrations" }
in your routes.rb file for devise to use your controller. - Once you get to the registration page to load you'll need to add first_name and last_name to your database otherwise you'll get no method errors.
I would start by straightening out these problems before diving into your current problem.
It might be worth stripping the code down to just what Tony has and get that working before you start adding your reports interface. I saw that your database has the roles lists as "super_admin", "global_user" and "internal_user" but you are calling camelize on the string before your query so I doubt that CanCan is working correctly in your environment.
One last thing, please make sure you change all the passwords and everything that you have shared - take a look at this post for a list of files to change.
To customise the views created by Devise first generate the them in your application.
rails generate devise:views
This imports all the views you need and you can them customise to your hearts content. This is the code from the new user view (/devise/registrations/new.html)
'<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>'
you will note that there is no @user - it is the use of @user that is throwing the undefined method model error.
No idea why resource is used and not @user but hopefully this will get you going.
精彩评论