Easy-peasy form objects
1. Puts the following code into controllers → concerns → application_shape.rb:
module ApplicationShape
extend ActiveSupport::Concern
module ClassMethods
delegate :model_name, to: :superclass
delegate :name, to: :superclass
end
end
2. Use it like this:
class ModerationArticleShape < Article
include ApplicationShape
validates :category, presence: true
end
def update
@article = ModerationArticleShape.find(params[:id])
if @article.update(params.require(:article))
redirect_to moderation_articles_path
else
render 'edit'
end
end