[英]RAILS simpler way to pass an update form than create a new route?
I have an order record that has multiple pipe/ funnel positions ( pipe_part ) each recorded by creation of a pipe_record that records who and when for that part. 我有一个订单记录,其中包含多个管道/漏斗位置(pipe_part),每个位置都是通过创建pipe_record来记录的,该管道记录了该部分的人员和时间。
I'm trying to create an update button that will post an edit to alter data in the pipe_record , so i iterate through the orders records then create a form for each position that already has a pipe_record then i want to either destroy or update , however I cant filter my recordset to make a form_for it returns a key issue 我正在尝试创建一个更新按钮,该按钮将发布编辑以更改pipe_record中的数据,因此我遍历订单记录,然后为每个已经具有pipe_record的位置创建一个表单,然后我要销毁或更新,但是我无法过滤我的记录集以形成一个form_,因为它返回了一个关键问题
<% @order.pipe.pipe_parts.order("priority").each do |part| %>
<% if @pipe_records.where("pipe_part_id= ?", part).present? %>
<td>
<% @pipe_position ||=part %>
<%= form_for @pipe_record.where("pipe_part_id= ?", part) do |f| %>
This throws a key error undefined method `to_key' for # Did you mean? 这会为#引发键错误未定义的方法“ to_key”。 to_query to_ary to_query to_ary
I created a second iteration of pipe_records in the controller incase was a cursor issue in the pipe_record recordset as below 我在控制器中创建了pipe_records的第二次迭代,以防在pipe_record记录集中出现光标问题,如下所示
@pipes=Pipe.all.order("name")
@pipe_records=@order.pipe_records
@pipe_record=@order.pipe_records
I tried to make an obj in the second itteration with 我试图在第二次尝试中制作一个obj
<% if @pipe_records.where("pipe_part_id= ?", part).present? do |pipe_record|%>
and then call 然后打电话
<%= form_for pipe_record do |f| %>
and am about to resort to creating a new route and controller for the update page as cant seem to get the id to pass to the @pipe_record but i know theres something obvious i've missed or structurally wrong in my solution. 并且将要为更新页面创建新的路由和控制器,因为似乎无法获取ID传递给@pipe_record,但我知道我的解决方案中有明显的遗漏或结构错误。
.first ! .first!
I forgot @pipe_record was a collection 我忘了@pipe_record是一个集合
<%= form_for @pipe_record.where("pipe_part_id= ?", part).first do |f| %>
Resolved 解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.