2
votes

I have a routing error that I simply cannot figure out! Its doing my head in, if anyone can suggest a solution that would be hugely appreciated.

I get the error: ROUTING ERROR No route matches {:action=>"create_from_template", :controller=>"projects"}

from the following button:

<p><%= link_to "Create from template", create_from_template_project_path %></p>

In routes.rb I have:

  resources :projects do
    member do
      get 'create_from_template'
    end
  end

In class ProjectsController I have:

  def create_from_template
    #@project = Project.find(params[:template_id])
    #@project.clone
    redirect_to projects_path
  end

It also shows up when I do "rake routes"

create_from_template_project GET    /projects/:id/create_from_template(.:format) {:action=>"create_from_template", :controller=>"projects"}

Anyone have any idea why it isnt working?

EDIT: Actually maybe I have misunderstood the "member" nested resource routing rules. I wasnt passing in a project. I have changed the button from

to

   <p><%= link_to "Create from template", create_from_template_project_path(template_project) %></p>

and now it works. Thanks everyone that helped.

2
Do you see the route in "rake routes" list?Lukas Stejskal
rake routes |grep create_from_templateAnatoly
yes i do, create_from_template_project GET /projects/:id/create_from_template(.:format) {:action=>"create_from_template", :controller=>"projects"}Nick
try sending the project in the path alongside link_toprasvin
i guess that worked, so i'll add it as an answer :)prasvin

2 Answers

4
votes

try sending the project in the path alongside link_to

3
votes

If you dont need to pass project for creating template action,change button as: `

 <%= link_to "Create from template", create_from_template_projects_path %> 
 member do 
 collection do 

If you use member do in routes.rb then you should pass project in the link_to as Prasvin has mentioned