class Project < ActiveRecord::Base
has_many :pages
attr_accessible :name, :class_name, :content, :style
def bulk_update_pages(attributes)
for a in attributes do
pages.find(a['id'].to_i).update_attributes(a) if pages.exists?(a['id'])
end
end
end
class Page < ActiveRecord::Base
belongs_to :project
end
是從項目批量更新頁面的好方法嗎? Project.find(session[:ProjectId]).bulk_update_pages(params)
從belongs_to模型批量更新has_many關係模型