私は奇妙な問題に直面しています。私は、スタッフに関連するすべてのタスクを表示しようとしている、と私は理解していないエラーがある:結合テーブルの要素を表示
- は、私はできたタスクのIDへのアクセスのみ
マイコード=
スタッフ指数:
<% @staffs.each do |staff| %>
<tr>
<td>
<%= link_to staff.name, staff %>
</td>
<%staff.tasks.each do |task| %>
<td>
<%= task.id %>/
</td>
<%end%>
</tr>
<% end %>
スタッフコントローラ:
class StaffsController < ApplicationController
before_action :authenticate_user!
skip_before_action :configure_sign_up_params
before_action :set_staff, only: [:show, :edit, :update, :destroy]
# GET /staffs
# GET /staffs.json
def index
@staffs = current_user.staffs
end
private
# Use callbacks to share common setup or constraints between actions.
def set_staff
@staff = Staff.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def staff_params
params.require(:staff).permit(:name, :user_id)
end
end
スタッフモデル:
class Staff < ActiveRecord::Base
has_one :user
has_many :ranches_staff
has_many :ranches, through: :ranches_staff
has_many :staffs_task
has_many :tasks, through: :staffs_task
accepts_nested_attributes_for :tasks, :allow_destroy => true
end
エラーを追加できますか?スタッフモデルを追加することもできます。 – Ursus
こんにちは@Ursus、あなたの答えのおかげで、私の誤差がある:#用 未定義のメソッド 'name」は、<タスク:0x007f83471b2818>私は私のポスト –