How to generate links with trailing slash in Rails 3?
You can add this to your application.rb:
config.action_controller.default_url_options = { :trailing_slash => true }
This way all routes will be generated with a trailing slash automatically, with no need to modify each link in your project.
Simply do as follows:
link_to 'Companies', companies_path(:trailing_slash => true)
I couldn't find any references, but adding trainling_slash: true
to the route definition also works (and avoids repeating oneself).
get 'companies/' => 'companies#index', :as => :companies, :trailing_slash => true
This was tested with Rails 3.2.13:
rails c1.9.3p327 :005 > app.companies_path=> "http://www.example.com/companies/