rails, adding a parameter to new route
routes, ruby-on-rails
Solution
Try:
resource ...
get "new/:template_id", :to => "Books#new_wp", :on => :collection
end
# GET /books/new/:template_id(.:format) Books#new_wp
Problem
The `new` action normally doesn't require parameters, since it creates a new resource from scratch. In my application whenever i create a certain type of resource say a `book` i need to provide a template, that is the id of another `book`. So my `new` route always has a parameter. I don't know how to represent this fact into `routes.rb` file. Since i don't even know whether it is feasible, just in the case it isn't, then i will create a new_wp, a "new with parameter" action. I tried to add it to my ``` resources :books, :only => [:edit, :update, :show, :new] do member do get 'new_wp/:template_id', :action => 'new_wp' end end ``` but rake routes say that it isn't quite what i want: ``` GET /books/:id/new_wp/:template_id(.:format) books#new_wp ``` that is, it has two params.