A
A
Artyom Lagun2014-03-19 18:27:10
Ruby on Rails
Artyom Lagun, 2014-03-19 18:27:10

How to set up routing in Ruby on Rails?

routing.rb:

get 'brand'  => 'index#brand',   as: :brand
  get 'client' => 'index#client',  as: :client
  get 'info'   => 'index#info',    as: :information
  get 'help'   => 'index#help',    as: :help

views/header.html.haml:
%nav#main_menu
    %ul.nav
      %li.home
        %a{href: root_url}
      %li
        %a{href: brand_path(page: 'brand')}
          %span
            о бренде
      %li
        %a{href: client_path(page: 'client')}
          %span
            клиентам
        %ul
          %li
            = link_to 'Наши партнёры и точки продаж', '#'
          %li
            = link_to 'Почему мы лучшие', '#'
          %li
            = link_to 'Готовое бизнес-решение', '#'
      %li
        %a{href: information_path(page: 'info')}
          %span
            полезная информация
      %li
        %a{href: help_path(page: 'contacts')}
          %span
            контакты

At the moment, the address is: localhost:3000/brand?page=brand. How to make it something like this: /pages?page=brand, /pages?page=client, /pages?page=info and /pages?page=contacts?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rubyruby, 2014-03-19
@Holzfaller

Not a very correct wish in terms of Rails conventions, but still possible, this requires:
match '/pages/:kind_of_page' => 'index#show', as: :page
in routes
and
in the show action you can resolve the behavior using redirect_to action_name_path

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question