Chap
Chap

Reputation: 3563

Custom RESTful route within has_many nesting

Projects have many tasks and a task has a custom RESTful action called 'approve'.

I'm expecting the helper to look something like this approve_project_task_url

This isn't working for me:

map.resources :projects,
              :has_many => :tasks,
                           :member => { :approve => :post }

Upvotes: 2

Views: 1250

Answers (2)

tsdbrown
tsdbrown

Reputation: 5048

I once had the same problem but I never searched long and hard for a fix. Instead I just opted for the older style which since then I've always used:

map.resources :projects do |project|
  project.resources :tasks, :member => {:approve => :post}
end

That will give you your required approve_project_task_url(@project, @task) routes/helpers.

I guess you may already know this approach? If so and you don't like it hopefully I'll learn something from your other responses :)

Upvotes: 10

Subba Rao
Subba Rao

Reputation: 10696

 **This is syntax correction to above solution**

map.resources :projects do |project|
  project.resources :tasks, :member => {:approve => :post}
end

Upvotes: 1

Related Questions