Вопрос

I am just getting started with RoR and have a basic question.

Currently I am creating simple static_pages e.g. about contact etc, for my application that will route as follow:

root "static_pages#home"
match "/about",   to: 'static_pages#about',   via: 'get'
match "/contact", to: 'static_pages#contact', via: 'get'

Which will look as follows:

  • localhost:3000/about
  • localhost:3000/contact

Now I would to create a sub directory called "legal" with an index page for the directory and other some pages, which will look like:

  • localhost:3000/legal
  • localhost3000:/legal/terms

Would I need to create a new controller to do this and include all the action or is there a way I can do this with my "StaticPages" controller some how?

Thanks in advance :)

Это было полезно?

Решение

You can do something like:

  scope '/legal' do
    match "/about",   to: 'static_pages#about',   via: 'get'
    match "/contact", to: 'static_pages#contact', via: 'get'
  end

For more info check out the guides for namespacing: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top