Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate is converting properties to nil and update doesn't generate a sql update statement
    text
    copied!<p>Rails 3.1 ruby 1.9.2p290 (2011-07-09) [i386-mingw32] sqlite3</p> <p>I have a model called usecase that is not creating or updating properly. When I create a new record the text columns are set to nil and the integer values based on select values are captured. There is also an integer value in an input field that is user supplied and it is set to nil.</p> <p>When I attempt an update the log shows that no sql input statement is created or executed. I am able to create new records and update them properly from the console.</p> <p>Here is the model code (note all validations have been removed):</p> <pre><code>class Usecase &lt; ActiveRecord::Base attr_accessible :due_at, :failure_end_condition, :frequency, :level_id, :number, :performance_target, :primary_actor_id, :priority_id, :profile_id, :project_id, :purpose, :success_end_condition, :title, :trigger, :usecase_status_id has_many :actor_assignments has_many :actors, :through =&gt; :actor_assignments has_many :pre_conditions has_many :post_conditions has_many :usecase_as_conditions has_many :scenarios has_many :variations belongs_to :profile belongs_to :project belongs_to :usecase_status </code></pre> <p>Here is the controller code for: class UsecasesController &lt; ApplicationController</p> <pre><code>def new @usecase = Usecase.new @usecase.profile_id = current_user.profile.id @usecase.set_defaults(current_user.profile.default_project_id) respond_to do |format| format.html # new.html.erb format.json { render json: @usecase } end end def edit @usecase = Usecase.find(params[:id]) respond_to do |format| format.html {render "edit"} format.json { render json: @usecase } end end def create @usecase = Usecase.new(params[:usecases]) respond_to do |format| if @usecase.save format.html { redirect_to [:edit, @usecase], notice: 'Usecase was successfully created.' } format.json { render json: @usecase, status: :created, location: @usecase } else format.html { render action: "new" } format.json { render json: @usecase.errors, status: :unprocessable_entity } end end end def update @usecase = Usecase.find(params[:id]) respond_to do |format| if @usecase.update_attributes(params[:usecases]) format.html { redirect_to @usecase, notice: 'Usecase was successfully updated.' } format.json { head :ok} else format.html { render action: "edit" } format.json { render json: @usecase.errors, status: :unprocessable_entity } end end end </code></pre> <p>Log For New Record Insert (note that the received parameter for :title has a value, but in the insert statement it is nil.</p> <pre><code> Started POST "/usecases" for 127.0.0.1 at 2012-01-24 14:50:40 -0800 Processing by UsecasesController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"Uscho1j5FCsbdRUhTyg/Ji79yyPwyMRZUcyiWYtSw54=", "usecase"=&gt;{"number"=&gt;"1", "title"=&gt;"Create New Record", "due_at"=&gt;"2012-02-07"}, "usecases"=&gt;{"project_id"=&gt;"2", "usecase_status_id"=&gt;"1", "profile_id"=&gt;"3"}, "commit"=&gt;"Create Usecase"} [1m[36mSQL (3.0ms)[0m [1m INSERT INTO "usecases" ("created_at", "due_at", "failure_end_condition", "frequency", "level_id", "lock_version", "number", "performance_target", "primary_actor_id", "priority_id", "profile_id", "project_id", "purpose", "success_end_condition", "title", "trigger", "updated_at", "usecase_status_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)[0m [["created_at", Tue, 24 Jan 2012 22:50:40 UTC +00:00], ["due_at", nil], ["failure_end_condition", nil], ["frequency", nil], ["level_id", nil], ["lock_version", 0], ["number", nil], ["performance_target", nil], ["primary_actor_id", nil], ["priority_id", nil], ["profile_id", 3], ["project_id", 2], ["purpose", nil], ["success_end_condition", nil], ["title", nil], ["trigger", nil], ["updated_at", Tue, 24 Jan 2012 22:50:40 UTC +00:00], ["usecase_status_id", 1]] Redirected to http://localhost:3000/usecases/2/edit Completed 302 Found in 71ms </code></pre> <p>Log for an update (note no UPDATE sql statement is created)</p> <pre><code> Started PUT "/usecases/2" for 127.0.0.1 at 2012-01-24 14:57:04 -0800 Processing by UsecasesController#update as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"Uscho1j5FCsbdRUhTyg/Ji79yyPwyMRZUcyiWYtSw54=", "usecase"=&gt;{"number"=&gt;"1", "project_id"=&gt;"2", "title"=&gt;"Update Row With New Title", "usecase_status_id"=&gt;"1", "due_at"=&gt;"2012-01-28", "profile_id"=&gt;"3"}, "commit"=&gt;"Update Usecase", "id"=&gt;"2"} [1m[36mUsecase Load (0.0ms)[0m [1mSELECT "usecases".* FROM "usecases" WHERE "usecases"."id" = ? LIMIT 1[0m [["id", "2"]] [1m[35mProject Load (1.0ms)[0m SELECT "projects".* FROM "projects" ORDER BY title ASC [1m[36mUsecaseStatus Load (1.0ms)[0m [1mSELECT "usecase_statuses".* FROM "usecase_statuses" ORDER BY rank ASC[0m [1m[35mProfile Load (0.0ms)[0m SELECT "profiles".* FROM "profiles" ORDER BY last_name ASC, first_name ASC Rendered usecases/test.html.erb within layouts/application (147.0ms) Rendered layouts/_stylesheets.html.erb (2.0ms) [1m[36mUser Load (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1[0m [1m[35mProfile Load (1.0ms)[0m SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = 3 LIMIT 1 [1m[36mAccount Load (0.0ms)[0m [1mSELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = 3 LIMIT 1[0m Rendered layouts/_header.html.erb (330.0ms) Rendered layouts/_footer.html.erb (0.0ms) Completed 200 OK in 674ms (Views: 614.0ms | ActiveRecord: 7.0ms) </code></pre> <p>Thanks for looking at this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload