0

因此,我使用 Basecamp HQ(经典)API 和Ruby Wrapper来设置 Rails 应用程序,以批量添加和删除待办事项、里程碑和消息。

Right now, I have two controllers--projects and projectSummary (projects has_many projectsummaries, and a projectsummary belongs_to a project) and I want to make it so when a project ID is selected rails will take you to a page that shows the to-do项目、里程碑和消息。

项目页面工作得很好。我想加载的关于该项目的所有信息都被很好地总结了,但是,当我试图链接到另一个页面时,我一直没有成功。

我得到的错误是

NoMethodError in Projects#index
...
undefined method `project_projectsummary_link'

即使我的 rake 路线返回

                      Prefix Verb   URI Pattern                                             Controller#Action
project_projectsummary_index GET    /projects/:project_id/projectsummary(.:format)          projectsummary#index
                             POST   /projects/:project_id/projectsummary(.:format)          projectsummary#create
  new_project_projectsummary GET    /projects/:project_id/projectsummary/new(.:format)      projectsummary#new
 edit_project_projectsummary GET    /projects/:project_id/projectsummary/:id/edit(.:format) projectsummary#edit
      project_projectsummary GET    /projects/:project_id/projectsummary/:id(.:format)      projectsummary#show
                             PATCH  /projects/:project_id/projectsummary/:id(.:format)      projectsummary#update
                             PUT    /projects/:project_id/projectsummary/:id(.:format)      projectsummary#update
                             DELETE /projects/:project_id/projectsummary/:id(.:format)      projectsummary#destroy
                    projects GET    /projects(.:format)                                     projects#index
                             POST   /projects(.:format)                                     projects#create
                 new_project GET    /projects/new(.:format)                                 projects#new
                edit_project GET    /projects/:id/edit(.:format)                            projects#edit
                     project GET    /projects/:id(.:format)                                 projects#show
                             PATCH  /projects/:id(.:format)                                 projects#update
                             PUT    /projects/:id(.:format)                                 projects#update
                             DELETE /projects/:id(.:format)                                 projects#destroy

目前,这是我index.html.erb尝试链接到页面以显示项目摘要的代码。

   <% @project.each do |item| %>
   <tr>
     <td><%= item.name %></td>
     <td><%= link_to item.id, project_projectsummary_link(@project) %></td>
     <td><%= item.last_changed_on %></td>
     <td><%= item.created_on %></td>
     <td><%= item.status %></td>

有什么想法可以让这个工作吗?

谢谢!

编辑

变成<%= link_to item.id, project_projectsummary_path(@project) %>

现在它返回带有错误的 URL 生成错误

No route matches {:action=>"show", :controller=>"projectsummary", :project_id=>#<...

我的 Routes.rb 目前是

ApiTest::Application.routes.draw do
  resources :projects do
    resources :projectsummary
  end

编辑 2

控制器代码

class ProjectsController < ApplicationController
  before_action :set_project, only: [:show, :edit, :update, :destroy]
  before_filter :basecamp_connect
  helper_method :sort_column, :sort_direction

  def index
    @project = Basecamp::Project.find(:all)
  end


  def list
    @projects = @basecamp.projects.find(:all)
  end

  def show
  end
4

1 回答 1

0

它应该是

<td><%= link_to item.id, project_projectsummary_path(:project_id => @project.id, :id => @project.projectsummary.id) %></td>

请注意,它path和不是link

我猜这个项目有一个项目摘要。

project_projectsummary GET    /projects/:project_id/projectsummary/:id(.:format)      projectsummary#show

您必须提供project_id并且id为了使路线正常工作

于 2013-12-17T18:37:32.887 回答