Note that there are some explanatory texts on larger screens.

plurals
  1. POAttribute changes are not notified and table is not updated
    text
    copied!<p>I want to update a table but the update SQL is not performed so the changes has no effect.</p> <p>Details:</p> <p>Originally issue.name us 'issue'. I want to change to 'qqqqqqqqqqqq'.</p> <p>Controller:</p> <pre><code>def update if params['cancel'] redirect_to(@issue) return end @issue = Issue.find(params[:id]) logger.debug "original object" logger.debug "#{@issue.to_yaml}" logger.debug 'bulk attribute settings...' @issue.attributes= params[:issue] logger.debug "after bulk settings" logger.debug "#{@issue.to_yaml}" @issue.events.build(:note=&gt;params[:issue][:description],:verb=&gt;'Edited', :changes=&gt;@issue.textalize_changes) if @issue.save logger.debug "after save" logger.debug "#{@issue.to_yaml}" redirect_to(@issue) else render :action =&gt; "edit" end end </code></pre> <p>One additional code fregment might be interesting is the <code>textalize_changes</code>:</p> <pre><code>def textalize_changes r = "" if changed? changes.keys.each do |k| r &lt;&lt; "#{k.humanize} changed " r &lt;&lt; "from `#{translate(k,changes[k][0])}` " r &lt;&lt; "to `#{translate(k,changes[k][1])}`" r &lt;&lt; "&lt;br/&gt;" end end r unless r.blank? end </code></pre> <p>The result:</p> <ul> <li>until the line <code>@issue.save</code> everything looks correct. I have checked that <code>@issue</code> contains all the changes i have made.</li> <li>on the user interface no changes I have notified.</li> <li>in the log no update SQL is visible. all relevant select and insert is presented but no update - so no change in table <code>issues</code></li> <li>even <code>textalize_changes</code> has not realize and changes in the object when checking for that (<code>changed?</code>)</li> <li>If I manually change the attribute in at source code level by <code>name=XXX</code> it is working.</li> </ul> <p>I don't know what to check or review at all. The code is so simple that i have no idea at all.</p> <p>Here is the log of the operation:</p> <pre><code> original object --- !ruby/object:Issue attributes: name: OTTO TEST 2 assigned_to: "29" updated_at: 2010-12-16 10:25:28 project_id: "1" current_estimate: lft: "1" original_estimate: priority: id: "10" version_id: area_id: description: worktype_id: "2" status_id: "5" rgt: "2" parent_id: created_at: 2010-05-21 07:37:15 fixed_in_version_id: attributes_cache: {} bulk attribute settings... WARNING: Can't mass-assign these protected attributes: description [4;36;1mIssue Load (0.0ms)[0m [0;1mSELECT "lft", "rgt", "parent_id" FROM "issues" WHERE ("issues"."id" = 10) [0m after bulk settings --- !ruby/object:Issue area: assigned_user: attributes: name: qqqqqqqqqq assigned_to: "29" updated_at: 2010-12-16 10:25:28 project_id: "1" current_estimate: lft: "1" original_estimate: priority: id: "10" version_id: area_id: description: worktype_id: "2" status_id: "5" rgt: "2" parent_id: created_at: 2010-05-21 07:37:15 fixed_in_version_id: attributes_cache: {} changed_attributes: {} children: events: fixed_in_version: iterations: marked_for_destruction: false parent: project: status: timelogs: version: work_items: worktype: [4;35;1mEvent Create (0.0ms)[0m [0mINSERT INTO "events" ("updated_at", "verb", "external", "issue_id", "note", "changes", "user_id", "created_at") VALUES('2010-12-16 10:33:08', 'Edited', 'f', 10, '', NULL, 1, '2010-12-16 10:33:08')[0m after save [4;36;1mEvent Load (16.0ms)[0m [0;1mSELECT * FROM "events" WHERE ("events".issue_id = 10) ORDER BY id ASC, created_at ASC[0m --- &amp;id001 !ruby/object:Issue area: assigned_user: attributes: name: qqqqqqqqqq assigned_to: "29" updated_at: 2010-12-16 10:25:28 project_id: "1" current_estimate: lft: "1" original_estimate: priority: id: "10" version_id: area_id: description: worktype_id: "2" status_id: "5" rgt: "2" parent_id: created_at: 2010-05-21 07:37:15 fixed_in_version_id: attributes_cache: {} </code></pre> <p>Technical info:</p> <ul> <li>Op system: winXP</li> <li>rails: rails 2.3.4</li> </ul> <p>Additional info:</p> <p>I have a bulk operation with the same purpose which is working correctly. I really don't know the differences:</p> <pre><code>def update_multiple if params['cancel'] redirect_to issues_path return end @issues = Issue.find(params[:issue_ids]) @issues.each do |issue| issue.attributes= params[:issue].reject {|k,v| v.blank? } issue.apply_template_on_name_change issue.events.build(:note=&gt;params[:issue][:description],:verb=&gt;"Edited", :changes=&gt;issue.textalize_changes) issue.save! end flash[:notice]="Issues updated!" redirect_to issues_path end </code></pre> <p>Additional info:</p> <p>If I replace <code>@issue.attributes= params[:issue]</code> by <code>@issue.attributes= params[:issue].reject {|k,v| v.blank? }</code> it apply changes and working. But it is not the one I really want. I want to change everything at once. I am going crazy.</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