Rails: manipulate URL query param keys before request hits controller -
i need pass params in url 3rd-party service user#new
.
due strong parameters controller expecting params in form user[name], user[email]. however, 3rd-party service blocking use of square brackets in param key.
what's easiest rails-y way work around this? perhaps in rails router? i'd take email=abc@example.com
, convert user[email]=abc@example.com
before request gets rejected controller.
thoughts?
thanks!
i think simple, manual solution best.
def user_params permitted_params = [:name, :email, :first_name, :last_name] params[:user].reverse_merge!(params.keep_if { |k,v| k.to_sym.in? permitted_params }) params.require(:user).permit(*permitted_params) end
if params[:user]
nil, can either this: params[:user] ||= {}
somewhere before merge.
or this: params[:user] = (params[:user] || {}).reverse_merge(params.keep_if { |k,v| k.to_sym.in? permitted_params }
Comments
Post a Comment