How to route my subfolder in Ruby on Rails views?

Can anyone shed some light on how to redirect .html.erb subcategory files? which fits as follows:

view/pages/en/index.html.erb 

and direct this i do the following things on route.rb

 match ':lang/index', :to => 'pages/en#index' 

and for the link code, I have this in the title

 <%= link_to "Home", index_path %> 

The error I get is

  Routing Error uninitialized constant Pages 

routes:

enter image description here

+6
source share
3 answers

AFAIK, Unable to jump to view. You can redirect the URL to a controller action. This action is responsible for displaying the views.

you can use routing with names to place resources in a subfolder.

...

What I wanted to write already written @TuteC. Just follow this link, and yes, you explain that you can get a specific personality.

+1
source

Namespaces organize your code and views in subfolders: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

If you only need the views/pages folder organized in this way, you can do something like this in the PagesController :

 render "#{I18n.locale}/#{action_name}" 

Question: why do you need view/pages/en/index.html.erb instead of view/pages/index.en.html.erb ? This will work out of the box.

+3
source

UPDATE Here's how it works for route.rb: -

 match ':lang/index', :to => 'pages#index' 

Repair it on your controller: -

 def index render "pages/en/index" end def about render "pages/#{params[:lang]}/about" end 
+2
source

All Articles