Ruby on rails ruby-rails读取表单参数

Ruby on rails ruby-rails读取表单参数,ruby-on-rails,ruby,parameters,Ruby On Rails,Ruby,Parameters,我正在尝试从html表单读取参数并更新数据库中的一些字段。。。 Html正在显示来自多个“故事”的数据,我希望能够更改Story.estimate字段。。。 html中的每个故事都有文本输入字段,如下所示: <%= text_field_tag story.id, story.estimate, :class => "input-small" %> 但这当然不起作用。。。我需要一些帮助。。。必须有一种更好、更简单的方法来做这件事……你应该试试 <%= text_fiel

我正在尝试从html表单读取参数并更新数据库中的一些字段。。。 Html正在显示来自多个“故事”的数据,我希望能够更改Story.estimate字段。。。 html中的每个故事都有文本输入字段,如下所示:

<%= text_field_tag story.id, story.estimate, :class => "input-small" %>
但这当然不起作用。。。我需要一些帮助。。。必须有一种更好、更简单的方法来做这件事……

你应该试试

<%= text_field_tag "story[#{story.id}]", story.estimate, :class => "input-small" %>

另外,我相信在rails 4中,update_属性可能已经被删除,以支持update_列。因此,如果您运行的是rails 4,这可能是一个问题。()

method.keys.to_我实际上做了什么?params[:story]应该像这个story=>{:id=>value}{123=>“example”}是的,我现在发现了问题。。。由于某些原因,参数[:story]看起来像这样{“'123'”=>example}这些双引号使to_i不起作用,它总是返回0是否可以显示您在控制器上获得的参数?更新了我的答案…删除了单引号表单文本_字段_标记..请现在使用参数检查
<%= text_field_tag "story[#{story.id}]", story.estimate, :class => "input-small" %>
if params[:story].present?
  id = params[:story].keys.to_i
  value = params[:story].values.first
  @story = Story.where(id: id).first
  #and then finally update the story 
  @story.update_attribute("estimate",value)

  OR

  #this will also update your story for the corresponding story id
  Story.where(id: id).update_all(estimate: value)
end