0
我有一個名爲「Project」的模型和一個名爲published的類方法?我決定是否發佈一個項目。我想創建一個基於這個類方法的範圍。什麼是正確的語法?對範圍使用類方法
這是我的Project.rb樣子:
class Project < ActiveRecord::Base
attr_accessible :title, :images_attributes, :ancestry, :user_id, :built, :remix
def published?
published = false
if remix_id.blank?
# check if the remix has been updated
if updated_at != created_at
published = true
end
else
# for non remixed projects, projects are published if the title has been updated and a picture has been uploaded
if title.starts_with("Untitled")
if images.count > 0
published = true
end
end
end
end
return published
end
我想:
scope :published, where(published? => true)
scope :published, where(:published? => true)