Rails - 保存到DB中的选项(onchange)

时间:2016-05-03 22:50:24

标签: ruby-on-rails ruby database sqlite

我正在尝试将选项保存到DB。 在保存在控制台中时在DB中获取此信息:

  • 右选择值:"result"=>"1"其1-4
  • 更新ID的正确值:"id"=>"4"其1-100

我会感激任何建议或帮助,试图找出几个小时。

但仍然收到此错误:

CONSOLE

Started POST "/update_result/4" for 65.200.165.210 at 2016-05-03 22:42:16 +0000
Cannot render console from 65.200.165.210! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by DashboardController#update_result as JS
  Parameters: {"utf8"=>"✓", "bitbucket"=>{"result"=>"1"}, "id"=>"4"}
  Bitbucket Load (0.5ms)  SELECT  "bitbuckets".* FROM "bitbuckets" WHERE "bitbuckets"."id" = ? LIMIT 1  [["id", 4]]
   (0.1ms)  begin transaction
   (0.2ms)  rollback transaction
Completed 500 Internal Server Error in 34ms (ActiveRecord: 0.8ms)

ArgumentError (When assigning attributes, you must pass a hash as an argument.):
  app/controllers/dashboard_controller.rb:13:in `update_result'


  Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (12.0ms)
  Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (5.9ms)
  Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (1.7ms)
  Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb (183.9ms)

路线

post 'update_result/:id', to: 'dashboard#update_result', as: :update_result

CONTROLLER

  def update_result
      @result = Bitbucket.find(params[:id])
      @result.update_attributes(params[:result])
  end

FORM IN VIEW

<%= form_for(commit, url: update_result_path(commit), :method => :post, :remote => true) do |r| %>
   <%= r.select :result, [['Waiting', 1], ['Success', 2], ['Broken - Not Submitted', 3], ['Broken - Quick Win', 4]], { selected: commit.result }, { onclick: "$(this).parent('form').submit();" } %>
<% end %>

DB MIGRATION

create_table :bitbuckets do |t|
  t.string :name
  t.text :message
  t.text :date
  t.datetime :remain, :null => false, :default => Time.now
  t.integer :assignee
  t.integer :result

  t.timestamps null: false
end

1 个答案:

答案 0 :(得分:0)

通过在控制器中添加私有函数来解决:

<强> CONTROLLER

java.sql.*