Re: [Rails] Validating user’s ability using CanCan with model associations

Dave Aronson
2010-07-23T12:12:18Z

On Thu, Jul 22, 2010 at 19:51, Carlos A. Cabrera
<carlos-x6sHsmbquPczbzzl3JCKVQ@public.gmane.org> wrote:

>  can :manage, TakeActionNote do |action, note|
>    note.take_action.user.id == user.id
>  end
> I can add notes to the take_action without any problem but when I try
> to destroy it I get:
>
> NoMethodError in Take action notesController#33 undefined method
> `take_action'' for nil:NilClass

Undefined methods on nil:NilClass mean that you''re expecting something
to be an object, but it''s really nil.  With something this short,
it''s
probably not so much *this* code, as whatever call it (or causes it to
be called, whatever).  If you don''t know what calls it, perhaps you
can insert something that would look for a nil value and dump the call
stack in that case.  (Sorry I can''t be more specific, as I
don''t know
CanCan myself; this is just a general code troubleshooting technique.)

-Dave

--
Specialization is for insects. | Professional: http://davearonson.com
-Robert Anson Heinlein         | Programming:  http://codosaur.us
-------------------------------+ Leadership:   http://dare2xl.com
Have Pun, Will Babble!  -me    | Et Cetera:    http://davearonson.net

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at