我有以下链接来发布项目:
# PATCH to a custom route called publish_project_path
= link_to 'Publish', publish_project_path(project), method: :patch
# in controller
def publish
@project.publish
redirect_to projects_url, notice: 'Project was successfully published.'
end
# in model
def publish
self.published = true
self.save!
end
# in routes
resources :projects do
member do
patch 'publish'
end
end
这是做这种事情的普遍接受的方式,其中属性是在模型中设置的,而不是通过 params 哈希传递?我的控制器操作是否甚至需要在这里修补?