How to bypass default_url_options?

In my last Rails project, I had to rewrite default_url_optionsin application_controller.rbto always pass a parameter through each request, for example:

def default_url_options 
  { :my_default_param => my_param_value }
end  

Now each URL helper appends my_default_param at the end of each generated URL. For example, it user_url(@current_user)generates a URL, for example:

http://www.example.com/users/1?&my_default_param=my_param_value 

But sometimes I need to generate a url without my_default_param . Is there any option that I can pass to the url helper so that user_url(@current_user, some_option: some_option_value) only returns:

http://www.example.com/users/1?&my_default_param=my_param_value

?

PN: I already tried with :overwrite_params=> { }, but it does not work, perhaps because it was evaluated before default_url_options.

And if not, is there another way to get the @current_user URL without my_default_param attached?

Thanks.

+2
1

default_url_options options, :

def default_url_options( options = {} )

  use_defaults = options.delete( :use_defaults )

  if use_defaults
    { :my_default_param => 'my_param_value' }
  else
    {}
  end

end

:

def default_url_options( options = {} )

  ignore_defaults = options.delete( :ignore_defaults )

  if ignore_defaults
    {}
  else
    { :my_default_param => 'my_param_value' }
  end

end
+4

Source: https://habr.com/ru/post/1709058/


All Articles