I''am still trying to make a system that gives users acces to edit their own posts. I build furtjer from the 32 of the rails recipe book called autorizing users with roles. So i create no a piece of code that does something but not the right thing. It''s only a test flash notice i don''t know wich code i must use def check_priviliges user = @session[''user''] unless user.adverts.detect{|advert| flash[:notice] = "right account i must find a way to give users to edit theri post"} flash[:notice] = "wrong accont" redirect_to :controller => "account", :action => "login" return false end end This does nothing at the moment but the problem is when a user clicks on edit he always get the first flash notice when he has at least one post. Maybe it sound a little bit stupid, so i have very little experience with programming. Ruby on Rails is my first language. I must always find a way to tell the program what it must do when user.adverts.detect{|advert| is correct. Maybe i must find the solotion elsewhere than in recipe 32. In this week i get a solotion from soemone but that was for another user system i guess. ror this i have a table adverts_users in the database that works well it gets the right rows at eac post. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Feb-17 15:08 UTC
Re: Users get acces to all posts when they placed one
I''m not sure what those adverts are [or what happened to the end of that Enumerable#detect block] but if you''ve got your Post belonging_to User and your User having_many Posts, then you should just check if that post''s user is the current user. Sound good? RSL On 2/16/07, GA Gorter <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''am still trying to make a system that gives users acces to edit their > own posts. > > I build furtjer from the 32 of the rails recipe book called autorizing > users with roles. > So i create no a piece of code that does something but not the right > thing. > It''s only a test flash notice i don''t know wich code i must use > > def check_priviliges > > user = @session[''user''] > unless user.adverts.detect{|advert| > flash[:notice] = "right account i must find a way to give users > to edit theri post"} > flash[:notice] = "wrong accont" > redirect_to :controller => "account", :action => "login" > return false > end > end > > This does nothing at the moment but the problem is when a user clicks on > edit he always get the first flash notice when he has at least one post. > > Maybe it sound a little bit stupid, so i have very little experience > with programming. Ruby on Rails is my first language. > I must always find a way to tell the program what it must do when > user.adverts.detect{|advert| is correct. > > Maybe i must find the solotion elsewhere than in recipe 32. In this week > i get a solotion from soemone but that was for another user system i > guess. > > ror this i have a table adverts_users in the database that works well it > gets the right rows at eac post. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---