Extending models

15 views
Skip to first unread message

fugee ohu

unread,
Jan 19, 2018, 7:55:54 AM1/19/18
to Refinery CMS
I don't understand this code, can someone explain please
Refinery::Admin::PagesController.class_eval do
  def page_params_with_my_params
    page_params_without_my_params.merge(params.require(:page).permit(:background_image_id))
  end
  alias_method_chain :page_params, :my_params
end

Philip Arndt

unread,
Jan 21, 2018, 5:02:50 PM1/21/18
to refine...@googlegroups.com
What this code is doing is overriding the default version of this method `page_params` with your own version that has custom functionality.
It's just adding more parameters to the list than exists by default to support a background_image_id parameter being passed to your controller via strong parameters.

Search 'alias_method_chain' for more information. This technique is more commonly done these days with `Module#prepend`.
Reply all
Reply to author
Forward
0 new messages