I’m trying to pass an object like that
<% if( can? :change, comment.karma, comment.user_id)%>
#blah blah blah
<% end %>
and in my ability.rb i have the following:
can :change, Karma do |karma, owner_id|
!karma.changers.map(&:user_id).include? user.id and owner_id != user.id
end
And every time I refresh the page cancan fires a query (from ability.rb) to get karma and then changers for that karma, even through I have already fetched it (using :include => { :karma => :changers } option for query in controller).
Added:
I have a guess that it’s happening because karma is storing a link to :include objects (not objects itself), which is actually get broken when I pass it to method. So I’m thinking about serialization now..
Any ideas?
When you do the query in the model try using this syntax
@comments = Comment.where(:foo_id => Bar.id).includes(:karma => :changers)and see if the problem persists.
For reference, http://m.onkey.org/active-record-query-interface has a great rundown of the new rails 3 active record querying syntax.