I am using Rails 4.2. In a gem, there is a route defined as
get 'book/:id', to: 'book#show', as: book
I'd like to add an additional dynamic segment in a custom route, so in the routes.rb file in my app, I have
get ':language/book/:id', to: 'book#show', as: language_book
Then in my controller, I tried to call the url helper
language_book_url language: :en, id: 3
I expect to get a url like http://host:port/en/book/3
, however, instead, I get http://host:port/book/3?language=en
. It seems I can't use the helper with that extra custom dynamic segment. Is it possible to get the desired path with the new dynamic segment variable? Thanks!
usmanali gave a answer in the comment, to use language_book_url :en, 3
. But what if I want a mixture of dynamic segments and query string params? So my target url is http://host:port/en/book/3?barcode=1234
. How can I call the url helper? A call to the helper like language_book_url('en', 3, barcode: 1234)
would produce http://host:port/book/3?language=en&barcode=1234
, instead of the expected one.