Forum: Ruby on Rails Users get acces to all posts when they placed one

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Fa342466c787830ea65ffc638d22d9c4?d=identicon&s=25 GG9 Rails (gorter9)
on 2007-02-16 17:45
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
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

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

ror this i have a table adverts_users in the database that works well it
gets the right rows at eac post.
70225136eacd3d870f64e03bff678655?d=identicon&s=25 Russell Norris (Guest)
on 2007-02-17 16:09
(Received via mailing list)
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
your User having_many Posts, then you should just check if that post's
is the current user. Sound good?

This topic is locked and can not be replied to.