I have overwritten to_param method in my Category model
def to_param
  name
end
And routes.rb
get '/:id' => 'categories#show', :as => :category
When name parameter doesn't contain any dots (foobar), all works right, but when it does (f.o.o.b.a.r)
I get an error No route matches [GET]. So my question is: is it possible to use dots in routing like a part of name of parameter? Or what can I do to accomplish this purpose, maybe some hooks or something. Any help is appreciated.
You can change the constraints for this route:
get ':/id' => "categories#show", :as => :category, :constraints => { :id => /[\w+\.]+/ }
This route will now match :id to any string containing any word character or a dot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With