开发者

Using non-English controllers in rails3

开发者 https://www.devze.com 2023-01-19 21:27 出处:网络
I have to following problem: If i want to follow the Rails naming convention i have to use the plural version of the model\'s name as my controller name.

I have to following problem:

If i want to follow the Rails naming convention i have to use the plural version of the model's name as my controller name.

Example:

rails g scaffold_controller Content

In this case i have a model(Content) and the previous command is going to generate a controller with the name Contents.

So what if I have a German website and I would like to use site.tld/inhalt/something-something instead of site.tld/contents/something-something.

I was thinking about two solutions:

a, use the German version of the word when I am generating the controller(afaik it is not supported by the scaffold_controller generator

b, generate the whole site(models, controllers) in English and route the specific request to a certain controller with named routes like:

match 'logout', :to => 'sessions#destroy'

In this case I can't use RESTful routes like:

resources :products

What do yo开发者_StackOverflow社区u think?


You can use routing configuration to change the url that matches this controller:

resources :contents, :path_names => { :new => 'neue', :edit => 'bearbeiten' }, :path => 'inhalt'

The contents_path method in your view will still work, but it'll output /inhalt as required and that will match. The /contents path won't match though. So if you call edit_content_path(@content) you'll get something like /inhalt/1/bearbeiten.

See Rails routing guide for more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消