0
我試圖將選項保存到數據庫。 聞聽此事在DB同時節省控制檯:Rails - 選項保存到數據庫(onchange)
- 右鍵選擇值:
"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)
ROUTES
post 'update_result/:id', to: 'dashboard#update_result', as: :update_result
控制器
def update_result
@result = Bitbucket.find(params[:id])
@result.update_attributes(params[:result])
end
FORM鑑於
<%= 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遷移
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