-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update the extending models guide for rails 4 and strong paramaters #2565
Conversation
@ugisozols what do you think? |
I think we need some kind of |
What about def page_params
super.permit(:extra_param)
end Does that work? It wouldn't allow the user to remove existing params, just add new ones. |
I'd prefer the extra method too. I tried the super.permit(:extra_params) and get:
I guess because we're actually overriding that method as opposed to sub classing it?? What if did the extra_params like this: def page_params
params.require(:page).permit(
*extra_params, :browser_title, :draft, :link_url, :menu_title, :meta_description,
:parent_id, :skip_to_first_child, :show_in_menu, :title, :view_template,
:layout_template, :main_photo_id, parts_attributes: [:id, :title, :body, :position]
).merge(extra_params)
end
def extra_params
[]
end Then we'd just need to overwrite extra_params. The only problem with that might be if another engine/gem needed to also permit params, how could it be done from more than one place? It'd be cool if we could just call a method from our decorator like |
Ah, of course.. it's not a subclass. This is the sort of thing that alias_method_chain was invented for.. even though it's deemed an anti-pattern. def page_params_with_my_ones
page_params_without_my_ones.permit(:extra_params)
end
alias_method_chain :page_params, :my_ones I'd rather not have to add even more "magic method" APIs to Refinery if we can help it. Sometimes I can see, with Devise, why you have to inherit all of their controllers to modify how it works at all. |
cool, I wasn't that familiar with I got this to work: Refinery::Admin::PagesController.class_eval do
def page_params_with_my_params
page_params_without_my_params.merge(params.require(:page).permit(:main_photo_id))
end
alias_method_chain :page_params, :my_params
end From reading a few posts, it does seem to be abused, but under the right circumstances, it's has a valid use. I'd say this is a good recommendation for it since we don't want to completely overwrite the method and we cannot subclass it. |
Ah yes, I totally forgot about @jess keen to update guide mentioning |
yes, I'll be glad to... |
what do you think? |
Looks good. @parndt? |
@jess looks good, can you please squash into a single commit for this change? |
make background image code format instead of overwriting the page_params method, recommend using alias_method_chain
@jess you just need to force push to this branch |
@parndt thanks for the tip, all done |
update the extending models guide for rails 4 and strong paramaters
Is this how you'd recommend doing it?