On Monday, April 15, 2013 8:46:22 AM UTC+1, Filip Matošić wrote:
>
> As zou have suggested i have done this by adding
> attr_writer :can_edit,:can_read
> to my model 
> and in my controller
> @scripts.each do |script|
> script[:can_edit]=can?(:edit,script)
> end
>

Having defined the accessor you do actually need to use it, e.g. 
script.can_edit = can?(:edit, script).

For it to be included in your to_json output, make it an attr_accessor (so 
that you get the reader method too) and use the :methods option to add it 
to the json output.

Fred 

> but still getting the warning
> guess I'm doing something wrong,
> can you lead me in the right direction?
>
> Dana ponedjeljak, 15. travnja 2013. 09:18:18 UTC+2, korisnik Filip Matošić 
> napisao je:
>>
>> Developing an application with angular I came into a problem. In my 
>> application I use cancan ( https://github.com/ryanb/cancan ).
>> Now when showing data in a table i have to filter if the logged user can 
>> or cannot edit, view etc, and thus disabling buttons that allow given 
>> operations.
>> When using ror its not a problem:
>> %td
>>         -if can? :edit,script
>> %a{:href=>edit_script_path(script)}
>> edit
>> but when i need to do the same thing with angular i need to mark the row 
>> data inside the controller with a flag eg. can_edit, can_view and then
>> so i come up with an idea to add an attribute to each row before 
>> rendering to json:
>>   
>> @scripts.each do |script|
>>    script[:can_edit]=can?(:edit,script)
>>  end
>>
>> but then i get the depriciation warning:
>> Writing arbitrary attributes on a model is deprecated. Please just use 
>> `attr_writer`
>>
>> An option to add columns can_edit, can_view to my table is out of the 
>> question,
>> allso taking the cancan logic into angular is allso not an option as I 
>> think that all of the logic is 
>> allready in cancan. So for me it comes down to how can I add the 
>> attributes that are not in my tables to models?
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/W1vBSt7bfnAJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to