On Monday, April 15, 2013 8:18:18 AM UTC+1, Filip Matošić wrote:
> 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:
> 
> 
As the warning suggests, I'd use attr_writer/attr_accessor. This doesn't mean 
adding columns to your database, just some ruby accessor methods (people 
sometimes call these virtual attributes)

Fred


> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>       @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/-/WywZ7LJnVVEJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to