开发者

Rails 3.1 Routing Error

开发者 https://www.devze.com 2023-03-22 11:57 出处:网络
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 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.


try sending the project in the path alongside link_to


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

0

精彩评论

暂无评论...
验证码 换一张
取 消