Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法`更新';用于阵列_Ruby On Rails_Ruby_Devise_Wicked Gem - Fatal编程技术网

Ruby on rails 未定义的方法`更新';用于阵列

Ruby on rails 未定义的方法`更新';用于阵列,ruby-on-rails,ruby,devise,wicked-gem,Ruby On Rails,Ruby,Devise,Wicked Gem,我正在尝试让邪恶的精灵宝石在我的Rails应用程序上运行。一旦用户注册应用程序(使用Desive),他们将重定向到此表单: income.html.erb <%= form_for @finance, url: wizard_path, :method => :put do |f| %> <div class="field"> What <strong>year</strong> were you born?<br>

我正在尝试让邪恶的精灵宝石在我的Rails应用程序上运行。一旦用户注册应用程序(使用Desive),他们将重定向到此表单:

income.html.erb

<%= form_for @finance, url: wizard_path, :method => :put do |f|  %>
  <div class="field">
    What <strong>year</strong> were you born?<br>
    <%= f.number_field :age %>
  </div>
  <div class="field">
    What's your <strong>zip code</strong>?<br>
    <%= f.number_field :zip %>
  </div>
  <%= f.submit %>
<% end %>
当我单击
submit
按钮时,出现以下错误:

NoMethodError in FinancesWelcomeController#update
undefined method `update' for #<Array:0x00000104c6ff48>
Extracted source (around line #14):
    def update
        @finance = Finance.find_all_by_user_id current_user[:id]
        **@finance.update(params[:finance])**
        render_wizard @finance
    end
FinanceSweeComeController中的命名错误#更新

#的未定义方法“update”。

启动
find_all_by
的方法将返回一个活动记录实例数组。。。不只是一个<代码>更新
仅适用于单个实例

因此,要么您希望遍历数组中的所有实例。。。使用
each
——或者您只想使用
find_by
而不是
find_all_by
获取第一个

在通过id查找的情况下。。。我建议将其更改为
find\u by
因此:


感谢您的回复-这似乎修复了表单提交错误,但不幸的是,数据实际上没有保存。我的用户与财务相关,当我点击我的表单编辑财务时,数据不会用向导提交的内容更新。@beaconhill-try
update\u attributes
。或者理想情况下
@finance.assign_属性(params[:finance]);金融,救命
`当我返回向导页面(/finance\u welcome/income,其中包含部分表单)时,它正在保存,但当我在实际的财务编辑页面(/finance/6/edit)时,它不会保存。您需要提供进一步的代码/信息供我们查看。您的表单是否在控制器中调用更新操作>?哪些参数将进入
params[:finance]
?这是你所期望的吗?等
NoMethodError in FinancesWelcomeController#update
undefined method `update' for #<Array:0x00000104c6ff48>
Extracted source (around line #14):
    def update
        @finance = Finance.find_all_by_user_id current_user[:id]
        **@finance.update(params[:finance])**
        render_wizard @finance
    end
@finance = Finance.find_by_user_id current_user[:id]
@finance.update_attributes(params[:finance])