ruby on rails - How to config route.rb when locale is sub-directory -
i tried configure localize setting on ror. though set along guide below, doesn't work correctly. http://guides.rubyonrails.org/i18n.html
here's code. here's simple restaurant list.
application_controller.rb
before_action :set_locale def set_locale i18n.locale = params[:locale] || i18n.default_locale end def default_url_options(options = {}) { locale: i18n.locale }.merge options end
routes.rb
# locale information scope "(:locale)" resources :restaurants end # example of regular route: 'restaurant/list' => 'restaurant#list' 'hello/index' => 'hello#index'
and results here.
routing error no route matches [get] "/en/restaurant/list"
you defining non restful route (list) outside scope, not inside. if need stick 'list', should define inside scope well:
# locale information scope "(:locale)" resources :restaurants :list, on: :collection end end
then go localhost:3000/en/restaurants/list , should have it.
Comments
Post a Comment