Users get acces to all posts when they placed one

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.

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs