【发布时间】:2014-03-03 19:05:43
【问题描述】:
我正在尝试查找要传递给 form_for 的考勤表 ID
这是我的控制器
def show
@time_id = current_user.time_sheets.find(params[:id])
if current_user
@current = current_user.time_sheets
else
redirect_to new_user_session_path, notice: 'You are not logged in.'
end
end
在我看来,这是我的 form_for:
<%= form_for(:entry, :url => {:controller => Entry, :action => 'create'}) do |f| %>
<table summary="Subject form fields">
<tr>
<th>Customer</th>
<td><%= f.text_field(:customer_name) %></td>
</tr>
<tr>
<th>Order Number</th>
<td><%= f.text_field(:order_number) %></td>
</tr>
<tr>
<th>Time In</th>
<td><%= f.text_field(:time_in) %></td>
</tr>
<tr>
<th>Time Out</th>
<td><%= f.text_field(:time_out) %></td>
</tr>
<tr>
<th>Time Sheet ID</th>
<td><%= f.hidden_field :time_sheet_id, value: @time_id.id %></td>
</tr>
</table>
<div class="form-buttons">
<%= submit_tag("Add Entry") %>
</div>
<% end %>
需要将时间表 ID 传递到 form_for 中,以便条目可以具有时间表 ID。
我有用户、时间表和条目。 user has_many time sheet,timesheets属于用户,用户有很多time sheet。条目属于时间表。
我收到此错误“找不到没有 ID 的 TimeSheet”
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 devise