【发布时间】:2019-09-20 06:36:25
【问题描述】:
我有一个名为“seo”的模型
class Seo < ApplicationRecord
belongs_to :seoable, polymorphic: true
# more code
end
我的应用程序中的许多模型 has_one seo。例如
class Post < ApplicationRecord
has_one :seo, as: :seoable
accepts_nested_attributes_for :seo, dependent: :destroy
# more code
end
我的问题是,让控制器中的参数保持干燥的最佳方法是什么。例如,我的 posts_controller 中有以下代码
def post_params
params.require(:post).permit(seo_attributes: [:id, :title, :meta_description, :etc])
end
每个模型都会重复上述内容。如何保持干燥?
【问题讨论】:
标签: ruby-on-rails ruby dry