I want to give the same parameters to all paths in Rails.

Asked 2 years ago, Updated 2 years ago, 43 views

Use url_options to include the same parameters in all paths of view, controller.

#application_controller.rb
def url_options
  { first: "first", last: "last"}
end

I did it like this, but

redirect_to user_path(name: "aaa")

gives parameters, whereas

redirect_to user_path

The url_options parameter is not included only if you do not have any arguments.
(url_options itself does not pass)
When I looked at the website that showed how to use url_options, I couldn't find this problem anywhere. How do I get parameters?

ruby ruby-on-rails

2022-09-30 16:20

1 Answers

I think it's better to write Ruby and Rails versions.

The method for doing the desired thing is default_url_options.

The phenomenon Haruka mentioned was that very old blog entries were caught in the search. In Rails 4.2.0, I tried a simple program and found that default_url_options was not a good idea. It didn't seem to reproduce.


2022-09-30 16:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.