RailsApps / rails3-bootstrap-devise-cancan

Outdated. See the rails-devise-pundit example app for Rails 4.1.
http://railsapps.github.io
491 stars 207 forks source link

Undefined local variable or method 'rolify' #48

Closed keenanpayne closed 10 years ago

keenanpayne commented 10 years ago

I had Devise up and working perfectly, but then when I went to set up CanCan and Rolify, I get this error in the browser:

NameError in Home#index

Showing C:/Sites/JustManage/app/views/devise/menu/_registration_items.html.erb where line #1 raised:

undefined local variable or method `rolify' for #<Class:0x3f48660>
Extracted source (around line #1):

1: <% if user_signed_in? %>
2: 
3:   <li>
4:      <%= link_to('Edit registration', edit_user_registration_path) %>
Trace of template inclusion: app/views/layouts/application.html.erb

Rails.root: C:/Sites/JustManage

user.rb

class User < ActiveRecord::Base
  rolify

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :subdomain, :first_name, :last_name

  # Make sure certain attributes are unique
  validates_uniqueness_of :email, :case_sensitive => false
end

role.rb

class Role < ActiveRecord::Base
  has_and_belongs_to_many :users, :join_table => :users_roles
  belongs_to :resource, :polymorphic => true

  scopify
end

rolify.rb

Rolify.configure do |config|
  config.use_dynamic_shortcuts
end

Let me know if you need me to post any contents from other files in my project, or anything of that nature.

DanielKehoe commented 10 years ago

Rails 3.2 or Rails 4?

keenanpayne commented 10 years ago

Ruby 1.9.3, Rails 3.2.1, and Rolify 3.2

DanielKehoe commented 10 years ago

What happens if you build the example application by running the command:

$ rails new rails3-bootstrap-devise-cancan -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb -T

I've tested the app with Ruby 1.9.3, Rails 3.2.1, and Rolify 3.2 and it runs.

If it runs on your local machine, you can compare the code to see where yours differs. Or maybe it would be easier to just use the starter app.

DanielKehoe commented 10 years ago

@keenanpayne You've closed the issue. What was the problem? May help others if you can report it.

keenanpayne commented 10 years ago

Oh of course, it was actually a simple solution!

See, I was trying to integrate Rolify and CanCan into my existing project that was using Devise. However (since I'm a beginner/intermediate using Ruby on Rails), I didn't know that when you change configuration files, you had to reset the server.

I closed the terminal that was running my server and then a few hours later when I wanted to start working on it again, everything was fine! I'm assuming that it was just my server that needed to be restarted.