2012-04-26 75 views
1

我有一個籃球應用程序,有多對多的關係,一個教練可以指導多個球隊,一個球隊可以有很多教練。Rails 3.2.x未定義方法'加入'

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

想法?我覺得這是小事我沒有看到......謝謝!

回答

1

我可以看到的一件事是錯誤的是,您的select中沒有coaches.id。您需要id才能使用coach_path(coach)。試試這個:

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

不知道這是否解決了join錯誤你得到。

+0

ahhh小提琴棒,我知道這是容易我看了。謝謝你讓我感覺自己很笨拙;夥計 – mrcolombo 2012-04-26 03:51:49

相關問題