1

コーチが複数のチームを指導でき、チームが多くのコーチを持つことができる、多対多の関係を持つバスケットボール アプリがあります。

Coaches_Controller.rb

  def index
    @coaches = Coach.joins(:teams).select("coaches.first_name, coaches.last_name, teams.team_level")

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @coaches }
    end
  end

Index.html.erb

<% @coaches.each do |coach| %>
      <tr>
        <td><%= link_to coach.first_name, coach_path(coach) %></td>
        <td><%= coach.last_name %></td>
        <td><%= coach.team_level %></td>
        <td>
          <%= link_to t('.edit', :default => t("helpers.links.edit")),
                      edit_coach_path(coach), :class => 'btn btn-mini' %>
          <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
                      coach_path(coach),
                      :method => :delete,
                      :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
                      :class => 'btn btn-mini btn-danger' %>
        </td>
      </tr>
    <% end %>

このエラーが発生していますが、その理由はよくわかりません...

http://i.stack.imgur.com/5a6oB.png

アイデア?見えない小さな何かのような気がします...ありがとう!

4

1 に答える 1

1

間違っていることがわかりますがcoaches.idselect. id動作するにはforが必要ですcoach_path(coach)。これを試して:

@coaches = Coach.joins(:teams).select("coaches.id, coaches.first_name, coaches.last_name, teams.team_level")

joinこれでエラーが解決するかどうかはわかりません。

于 2012-04-26T02:47:32.090 に答える