Renaming Routing Helpers in Rails 3 Routing

I have a controller / project model. Instead of listing projects on the #index page, I show a list of drop-down lists that are sent to # select projects, which finds the correct project (I made sure there can only be 1 for each combination of options) and sends the user to the #show page for of this project.

So, for my routes, I do this ...

resources :projects, :only => [:index, :show] do
  collection do
    get 'select'
  end
end

And that’s fine, but the helper method for #select is select_projects, which is understandable, but in my case I really want select_project. And I really don't want this to be written in another file. No problem, I can use: how ...

resources :projects, :only => [:index, :show] do
  collection do
    get 'select', :as => 'select_project'
  end
end

- "select_project_projects". ( , )...

resources :projects, :only => [:index, :show]
match '/projects/select', :to => 'projects#select', :as => 'select_project'

, , , /project/select 'show # show'. .

match '/projects/select', :to => 'projects#select', :as => 'select_project'
resources :projects, :only => [:index, :show]

? , OCD, .

+3
3

+2

, , , , :

resources :projects, :only => [:index, :show] do
  member do
    get 'select'
  end
end

select_project.

+1

, ( ):

resources :posts, as: "articles"
0

Source: https://habr.com/ru/post/1775767/


All Articles