ruby - Rails routes formatted params in URL -


i have following in routes:

match '/car-rentals(/:address)' => 'search#search', via: :get 

i can visit:

localhost:3000/car-rentals/montreal

shows available cars montreal.

when enter: localhost:3000/car-rentals/montreal quebec

my url becomes localhost:3000/car-rentals/montreal%20quebec

i be: localhost:3000/car-rentals/montreal-quebec

i tried using to_param in model.

class search < activerecord::base   def to_param     "#{address.parameterize}"   end end 

any other ways achieve this?

also worth mentioning. when stick binding.pry in to_param , reload page, doesn't stop process, not getting there.

  def to_param     binding.pry # on page load, not getting here     "#{address.parameterize}"   end 

thanks in advance!

there several gems generate slugs seo friendly urls.

i've used https://github.com/norman/friendly_id in past , worked fine. has helpful documentation.

there this: https://github.com/sutto/slugged


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -