ruby on rails - Using Class Method for Scope -


i have model called "project" , class method called published? determined whether project published. i'd create scope based on class method. correct syntax?

this project.rb looks like:

class project < activerecord::base   attr_accessible :title, :images_attributes, :ancestry, :user_id, :built, :remix  def published?     published = false     if remix_id.blank?       # check if remix has been updated       if updated_at != created_at         published = true       end     else       # non remixed projects, projects published if title has been updated , picture has been uploaded       if title.starts_with("untitled")         if images.count > 0           published = true         end       end     end   end   return published end 

i tried:

scope :published, where(published? => true)

scope :published, where(:published? => true)

i wanted avoid creating column project model, created 1 called published , set value based on published? method. update column accordingly , use scope.


Comments