Question

So I'm using the Basecamp HQ (classic) API and a Ruby Wrapper to set up a Rails application to mass add and delete to-do items, milestones and messages.

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 items, milestones and messages.

The projects page works just fine. All the information I want to load about the project is summarized beautifully, however, when trying to link to another page I have been very unsuccessful in proceeding.

The error I'm getting is a

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

Even though my rake routes returns

                      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

Currently, this is my index.html.erb code where I try to link to a page to show the project summary.

   <% @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>

Any ideas what I could do to get this working?

Thanks!

EDIT

Changed to <%= link_to item.id, project_projectsummary_path(@project) %>

Now it returns a URL generation error with the error

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

My Routes.rb is currently

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

Edit 2

Controller Code

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
Was it helpful?

Solution

it should be

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

Notice that its path and not link.

I am guessing that project has_one projectsummary.

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

you will have to provide project_id and id in order for the route to work properly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top