2

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.

5
  • Do you see the route in "rake routes" list? Commented Jul 25, 2011 at 8:27
  • rake routes |grep create_from_template Commented Jul 25, 2011 at 8:27
  • yes i do, create_from_template_project GET /projects/:id/create_from_template(.:format) {:action=>"create_from_template", :controller=>"projects"} Commented Jul 25, 2011 at 8:31
  • 4
    try sending the project in the path alongside link_to Commented Jul 25, 2011 at 8:34
  • 3
    i guess that worked, so i'll add it as an answer :) Commented Jul 25, 2011 at 8:42

2 Answers 2

4

try sending the project in the path alongside link_to

Sign up to request clarification or add additional context in comments.

Comments

3

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

 <%= link_to "Create from template", create_from_template_projects_path %> 
In routes, instead of
 member do 
you should use
 collection do 

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.