How to set defaults for parameters of url helper methods?

后端 未结 3 1424
盖世英雄少女心
盖世英雄少女心 2021-02-06 07:15

I use language code as a prefix, e.g. www.mydomain.com/en/posts/1. This is what I did in routes.rb:

scope \":lang\" do
  resources :posts
end
         


        
3条回答
  •  青春惊慌失措
    2021-02-06 07:46

    doesterr above has almost got it. That version of default_url_options won't play nice with others. You want to augment instead of clobber options passed in:

    def locale_from_cookie
      # retrieve the locale
    end
    
    def default_url_options(options = {})
      options.merge(:lang => locale_from_cookie)
    end
    

提交回复
热议问题