Thursday, 15 September 2011

ruby on rails - undefined method `role?' for nil:NilClass -



ruby on rails - undefined method `role?' for nil:NilClass -

i trying utilize cancan on rails application. followed same tutorial used on other project , got working. next set followed:

it seems when seek access application given

undefined method `role?' nil:nilclass

which points next line of application/layout.html.erb

<% if @user.role? :administrator %>

the problem @user not defined in every controller action, layout beingness rendered on every controller action, @user null. prepare this, check @user defined in if statement this:

<% if @user && @user.role?(:administrator) %>

ruby-on-rails cancan

No comments:

Post a Comment