以下是我的模型:
class Ticket < ActiveRecord::Base
attr_accessible :issue, :logs_attributes
has_many :logs
accepts_nested_attributes_for :logs
end
class Log < ActiveRecord::Base
attr_accessible :detail, :ticket_id
belongs_to :ticket
end
我试图弄清楚如何通过工单视图创建新日志,但我无法显示日志模型中的详细信息字段。我对观点的尝试:
门票表格
<%= form_for(@ticket) do |f| %>
<% if ... end %>
<div class="field">
<%= f.label :issue %><br />
<%= f.text_area :issue %>
</div>
<% f.fields_for :logs do |builder| %>
<p>
<%= builder.label :detail %><br />
<%= builder.text_area :detail %>
</p>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
门票\表演
<p id="notice"><%= notice %></p>
<p>
<b>Issue:</b>
<%= @ticket.issue %>
</p>
<ol>
<% for log in @ticket.logs %>
<p>
<%=log.detail %> *Note:squiggly line under detail said "Cannot find 'detail'"*
</p>
<% end %>
</ol>
<%= link_to 'Edit', edit_ticket_path(@ticket) %> |
<%= link_to 'Back', tickets_path %>
我的控制器:
def new
@ticket = Ticket.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @ticket }
end
end
def create
@ticket = Ticket.new(params[:ticket])
respond_to do |format|
if @ticket.save
format.html { redirect_to @ticket, notice: 'Ticket was successfully created.' }
format.json { render json: @ticket, status: :created, location: @ticket }
else
format.html { render action: "new" }
format.json { render json: @ticket.errors, status: :unprocessable_entity }
end
end
end
门票\演出
<h1>New ticket</h1>
<%= render 'form' %>
<%= link_to 'Back', tickets_path %>