What am I doing wrong here? I am using cancan on Rails 3. In my
Ability class, I''ve got:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user, for users who are not registered
or don''t have an account yet
if user.role? :admin
can :manage, :all
elsif user.role? :artist
can :read, [Artist, Painting, Video]
can :manage, Video do |video|
video.try(:user) == user
end
else
can :create, [Artist]
can :read, :all
end
end
end
In VideosController#index, I have:
<% if can? :update, song %>
<div class="interaction clearfix">
<%= link_to ''edit'', ''#''
%>
<%= link_to ''delete'', ''#'',
:class => ''last'' %>
</div>
<% end %>
I get:
undefined method `user'' for :index:Symbol
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-12 13:05 UTC
Re: Cancan, how to allow artists to edit their own
By the way. I am using Devise, if that even matters On Oct 12, 8:41 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What am I doing wrong here? I am using cancan on Rails 3. In my > Ability class, I''ve got: > > class Ability > include CanCan::Ability > > def initialize(user) > user ||= User.new # guest user, for users who are not registered > or don''t have an account yet > > if user.role? :admin > can :manage, :all > elsif user.role? :artist > can :read, [Artist, Painting, Video] > can :manage, Video do |video| > video.try(:user) == user > end > else > can :create, [Artist] > can :read, :all > end > end > end > > In VideosController#index, I have: > > <% if can? :update, song %> > <div class="interaction clearfix"> > <%= link_to ''edit'', ''#'' %> > <%= link_to ''delete'', ''#'', :class => ''last'' %> > </div> > <% end %> > > I get: > > undefined method `user'' for :index:Symbol-- 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 http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-12 13:07 UTC
Re: Cancan, how to allow artists to edit their own
Small code typo. In VideoController#index. It should have been:
<% if can? :update, video %>
<div class="interaction clearfix">
<%= link_to ''edit'', ''#''
%>
<%= link_to ''delete'', ''#'',
:class => ''last'' %>
</div>
<% end %>
On Oct 12, 9:05 pm, Christian Fazzini
<christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> By the way. I am using Devise, if that even matters
>
> On Oct 12, 8:41 pm, Christian Fazzini
<christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>
> > What am I doing wrong here? I am using cancan on Rails 3. In my
> > Ability class, I''ve got:
>
> > class Ability
> > include CanCan::Ability
>
> > def initialize(user)
> > user ||= User.new # guest user, for users who are not registered
> > or don''t have an account yet
>
> > if user.role? :admin
> > can :manage, :all
> > elsif user.role? :artist
> > can :read, [Artist, Painting, Video]
> > can :manage, Video do |video|
> > video.try(:user) == user
> > end
> > else
> > can :create, [Artist]
> > can :read, :all
> > end
> > end
> > end
>
> > In VideosController#index, I have:
>
> > <% if can? :update, song %>
> > <div class="interaction clearfix">
> > <%= link_to ''edit'',
''#'' %>
> > <%= link_to ''delete'',
''#'', :class => ''last'' %>
> > </div>
> > <% end %>
>
> > I get:
>
> > undefined method `user'' for :index:Symbol
>
>
--
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
http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-12 13:27 UTC
Re: Cancan, how to allow artists to edit their own
Any thoughts? Also worth noting that Video and Paintings inherit from Media. Media is an STI On Oct 12, 9:07 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Small code typo. In VideoController#index. It should have been: > > <% if can? :update, video %> > <div class="interaction clearfix"> > <%= link_to ''edit'', ''#'' %> > <%= link_to ''delete'', ''#'', :class => ''last'' %> > </div> > <% end %> > > On Oct 12, 9:05 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > By the way. I am using Devise, if that even matters > > > On Oct 12, 8:41 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > What am I doing wrong here? I am using cancan on Rails 3. In my > > > Ability class, I''ve got: > > > > class Ability > > > include CanCan::Ability > > > > def initialize(user) > > > user ||= User.new # guest user, for users who are not registered > > > or don''t have an account yet > > > > if user.role? :admin > > > can :manage, :all > > > elsif user.role? :artist > > > can :read, [Artist, Painting, Video] > > > can :manage, Video do |video| > > > video.try(:user) == user > > > end > > > else > > > can :create, [Artist] > > > can :read, :all > > > end > > > end > > > end > > > > In VideosController#index, I have: > > > > <% if can? :update, song %> > > > <div class="interaction clearfix"> > > > <%= link_to ''edit'', ''#'' %> > > > <%= link_to ''delete'', ''#'', :class => ''last'' %> > > > </div> > > > <% end %> > > > > I get: > > > > undefined method `user'' for :index:Symbol > >-- 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 http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Oct-12 14:00 UTC
Re: Re: Cancan, how to allow artists to edit their own
What is the last error you got? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-12 14:44 UTC
Re: Cancan, how to allow artists to edit their own
undefined method `user'' for :index:Symbol On Oct 12, 10:00 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What is the last error you got?-- 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 http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-12 14:55 UTC
Re: Cancan, how to allow artists to edit their own
does cancan expect me to have a user method in my user model or something? On Oct 12, 10:44 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> undefined method `user'' for :index:Symbol > > On Oct 12, 10:00 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What is the last error you got? > >-- 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 http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-12 15:34 UTC
Re: Cancan, how to allow artists to edit their own
Ok... I must have been using old cancan code. Back when I was still on Rails 2.3.8. The new doc says: can :manage, Painting, :artist_id => user.artist.id Which now seems to work without any errors On Oct 12, 10:55 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> does cancan expect me to have a user method in my user model or > something? > > On Oct 12, 10:44 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > undefined method `user'' for :index:Symbol > > > On Oct 12, 10:00 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > What is the last error you got? > >-- 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 http://groups.google.com/group/rubyonrails-talk?hl=en.