문제

Adding a trailing slash in your links is easy enough with {:trailing_slash => true}, but this doesn't account for if a user types in a non-slashed url. Is there a way to enforce trailing slashes via redirects in the router?

get "/:controller/:id" => redirect{|params| "/#{params[:controller]}/#{params[:id]}/" }

The above leads to a circular loop.

Why?

a relative link of "./subclass" on

/parent/1

is much different than

/parent/1/
도움이 되었습니까?

해결책

in the config/application.rb file, add

config.action_controller.default_url_options = { :trailing_slash => true }

in the Application class

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top