Hi Colin, :conditions active_post is meant to only display posts that are active.
If a user deletes a post (they think it's deleted, but infact it is archived and just set as inactive) as I may want to do something with it at a later date on the site. I looked on the rails api site, I was therefore kinda hoping that : Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions => "active_post = 1", :order => "created_at desc") would only return posts where the active flag is set to 1. What i've done is maybe wrong, but i hope that explanation makes sense....? On 8 Dec, 20:50, Colin Law <[email protected]> wrote: > 2009/12/8 RubyonRails_newbie <[email protected]>: > > > > > > > Hi there, > > > I've decided that instead of deleting all posts on a user's profile, > > there is now an active_post column in the posts table. > > > Basically, a user has only 1 active post at a time, and the database > > is either a value of 0 (inactive) or 1(active) > > > I have a problem though. When i add a post, I see that the active > > column is set to 1. > > When I add a 2nd post, the most recent is set to active_post = 1 and > > the initial post is set to 0. (this is as i expect). > > > However - if I delete a post using the link on the page, the database > > value sets to 0 (also what I want and expect) > > > But - the last post is still displayed on the page. > > > Below is the code on the posts controller, that hopefully explains > > what I'm doing: > > > Basically - does anyone know how to hide this post? (as it stands the > > posts for this user are inactive, so should not be visible to them) > > > I think it's to do with the :conditions. > > > def index > > �...@posts = Post.find_by_user_id( session[:user_id], :order => > > "created_at DESC") > > Post.find_by_user_id( session[:user_id], 1, :limit => > > 1, :conditions => "active_post", :order => "created_at desc") > > Can you explain what :conditions => "active_post" is supposed to do? > Possibly you should be comparing the value of active_post with some > value? > > Colin -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

