我試圖創建一個類似系統的評論,其中用戶可以向「決定」添加「結果」。在show.html.erb中渲染時未定義的局部變量或方法
現在我已經呈現的形式和的「決定」,但成果show.html.erb成果提供以下錯誤:未定義的局部變量或方法'成果的#<#:0x007fc6046099e8>
我的代碼:
控制器/ outcomes_controller.rb
class OutcomesController < ApplicationController
def create
@decision = Decision.find(params[:decision_id])
@outcome = @decision.outcomes.create(params[:outcome].permit(:actual, :strength, :weakness))
redirect_to decision_path(@decision)
end
end
型號/ outcome.rb
class Outcome < ActiveRecord::Base
belongs_to :decision
end
型號/ decision.rb
class Decision < ActiveRecord::Base
has_many :outcomes
end
決定/ show.html.erb
<h1>Decision showpage</h1>
<h2><%= @decision.title %></h2>
<p><%= @decision.created_at %></p>
<p><%= @decision.forecast %></p>
<p><%= @decision.review_date %></p>
<%= render @decision.outcomes %>
<%= link_to "Delete Decision", decision_path(@decision), method: :delete, data: { confirm: "Are you sure?" } %>
<%= render "outcomes/form" %>
<%= render "outcomes/outcome" %>
結果/ _form.html.erb
<%= form_for([@decision, @decision.outcomes.build]) do |f| %>
<%= f.label :actual %>:
<%= f.text_field :actual %> <br/>
<%= f.label :strength %>:
<%= f.text_area :strength %> <br/>
<%= f.label :weakness %>:
<%= f.text_area :weakness %> <br/>
<%= f.submit %>
<% end %>
結果/ _outcome.html.erb
<%= outcomes.actual %>
<%= outcomes.strength %>
<%= outcomes.weakness %>
任何人都可以通過解釋爲什麼發生此錯誤以及我能做些什麼來幫助我解決問題嗎?
哪行代碼是你得到的錯誤? – Huy
這可能是你需要將你的變量傳遞給你的部分。 – Huy
@Huy錯誤發生在results/_outcome.html.erb文件中<%= outcomes.actual%>上。你有什麼建議我可以將變量傳遞給部分? – Hiltsje