mardi 3 mai 2016

Rails - Options saving into DB (onchange)

I'm trying to save options to DB. Getting this in DB while saving in console:

  • Right selected value: "result"=>"1" its 1-4
  • Right value of updating id: "id"=>"4" its 1-100

I'll appreciate any advice or help with that, trying to figured out for couple hours.

But still getting this error:

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

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

Aucun commentaire:

Enregistrer un commentaire