Can anyone please shed some light on how to route your sub-folder's .html.erb files?? which is placed like this:
view/pages/en/index.html.erb
and to route this i am doing following things on route.rb
match ':lang/index', :to => 'pages/en#index'
and for a link code, I have this on the header
<%= link_to "Home", index_path %>
The error i am getting is
Routing Error
uninitialized constant Pages
routes:
Namespaces will organize your code and views in subfolders: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing
If just need only the views/pages
folder organized that way, you could do in PagesController
something like:
render "#{I18n.locale}/#{action_name}"
A question: why would you like view/pages/en/index.html.erb
instead of view/pages/index.en.html.erb
? That would work out of the box.
UPDATE This is how it works for route.rb:-
match ':lang/index', :to => 'pages#index'
Render it on your controller:-
def index
render "pages/en/index"
end
def about
render "pages/#{params[:lang]}/about"
end
AFAIK, There is no way to route to a view. You can route an URL to a controller's action. That action is responsible for rendering the views.
you can use namespaced routing to put the resources in the sub folder.
...
What i wanted to write already written by @TuteC. Just follow that link and yes you can get language specific thing out of box as he explained.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With