简体   繁体   English

Rails布线问题

[英]Rails Routing Questions

I am very new to Ruby on Rails and I have been working with a project while learning but I have run into an issue. 我是Ruby on Rails的新手,在学习时一直在从事一个项目的工作,但遇到了问题。 I am trying to set up a link from a view under a "task" controller to a view for new timetracks. 我正在尝试从“任务”控制器下的视图建立到新时间轨迹视图的链接。 I am attempting to link on the view like so: 我试图像这样链接视图:

<%= link_to "New Timetrack", new_project_list_task_timetrack_path(@project, @list, @task) %>

And I am getting this error: 我收到此错误:

No route matches {:action=>"new", :controller=>"timetracks", :project_id=>nil, :list_id=># < List id: 1, name: "Test", description: "Test", created_at: "2013-12-18 21:00:39", updated_at: "2013-12-18 21:00:50", project_id: 1, default: nil>, :task_id=>#>Task id: 1, description: "First Task", completed: false, list_id: 1, created_at: "2013-12-18 21:00:57", updated_at: "2013-12-18 21:00:57", default: nil>} 没有路由匹配{:action =>“ new”,:controller =>“ timetracks”,:project_id => nil,:list_id =>#<列表ID:1,名称:“ Test”,描述:“ Test”,created_at :“ 2013-12-18 21:00:39”,Updated_at:“ 2013-12-18 21:00:50”,project_id:1,默认值:nil>,:task_id =>#>任务ID:1,说明:“第一个任务”,已完成:false,list_id:1,created_at:“ 2013-12-18 21:00:57”,updated_at:“ 2013-12-18 21:00:57”,默认值:nil>}

I made sure that there was an action "new" in the timetracks controller. 我确保时间跟踪控制器中有一个动作“ new”。 I am creating the link the way above because of how I saw Rails scaffold the relation between projects and lists which was like so: 我按照上面的方式创建链接,因为我看到Rails脚手架的是项目和列表之间的关系,如下所示:

<%= link_to "Create To-Do", new_project_list_path(@project) %>

So I'm stumped and would like some help. 所以我很困惑,想要一些帮助。 Any information is appreciated! 任何信息表示赞赏!

尝试使用new_project_timetrack_path如果没有帮助,请查看bash命令rake routes的输出,并找到所需的路由。

in your config/routes.rb must be rows like these: 您的config / routes.rb中必须是以下行:

resources :projects do    
  resources :lists do    
    resources :tasks do    
      resources :timetracks    
    end
  end
end

and then rake compile path like 然后像这样耙编译路径

host:3000/projects/<project_id>/lists/<list_id>/tasks/<task_id>/timetracks/new

I hope this can help you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM