ruby on rails - Trying to add conditions to controller .find method -
having few issues starting out rails.
i'm creating directory, initially, additions displayed approved false until manually approve them.
i'm creating admin interface can click 'approve' need display listings attribute of approved = false.
here's code:
def listings @listings = listing.find(:all, :conditions => "approved = false") end
and here's error
couldn't find listings 'id': (all, {:conditions=>"approved = false"}) (found 0 results, looking 2)
a little help brilliant, thanks!
you using old find
syntax (rails 2.0).
the newer syntax no longer uses :all, , no longer passes conditions find
method. assuming using rails 4, equivalent is
def listings @listings = listing.where(approved: false) end
you can utilize .all
, it's syntactic sugar in case.
def listings @listings = listing.where(approved: false).all end
ruby-on-rails ruby rails-activerecord
No comments:
Post a Comment