ruby - Rails 4 - routing using concerns -


i trying figure out how use concerns in routes file.

i have models called user, project , eoi.

the associations are:

user

has_many :eois 

project

has_many :eois 

eoi

belongs_to :user belongs_to :project 

i trying make system show eois have been submitted on project, visible user made project.

separately, want show every user of eois user made (regardless of project made on).

i think want nested routes first scenario , want eoi routes not nested second scenario.

in routes.rb

i have:

resources :projects     # concerns: :eois,      member     resources :eois   end 

i want have:

resources :eois 

how can make work? can't hang of examples in http://api.rubyonrails.org/classes/actiondispatch/routing/mapper/concerns.html

i don't understand whether commendable in example model or if need write able have routes in 2 places in routes.rb file.

my next attempt try copy gist of example in above link, have

resources :eois#, only: [:index]   concern :eoiable     resources :eois   end  resources :projects     concerns :eoiable   end 

i'm not sure if need make definition somewhere working.

route concerns needed when want dry routes. far have 1 route duplication (eoi) so... using concern overkill here.

what want have 2 eoi controllers, 1 responsible providing eois, second ones inside project.

for better readability i'd namespace them – put 1 eois_controller.rb inside projects folder , named projects::eoiscontroller, second 1 - top-level controller, named eoiscontroller. routes this:

resources :eois # map eoiscontroller resources :projects   scope module: :projects     resouces :eois # map projects::eoiscontroller   end end 

and, of course, might want dry these 2 controllers afterwards.


Comments