Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveRecord not updating attribute
    primarykey
    data
    text
    <p>Here is a code snippet and its resulting output. The code appears to update the attribute, but when I check the record manually in the database, there is no change. This is confirmed by .changed? returning false. What have I done wrong?</p> <pre><code>class Ticket &lt; ActiveRecord::Base ##+-----------------+-----------------------+------+-----+---------+-------+ ##| Field | Type | Null | Key | Default | Extra | ##+-----------------+-----------------------+------+-----+---------+-------+ ##| ticketid | bigint(20) unsigned | NO | PRI | NULL | | ##| ticketnumber | bigint(20) unsigned | NO | | NULL | | ##| contactname | char(40) | YES | | NULL | | ##| department | char(40) | YES | | NULL | | ##| tech | char(40) | YES | | NULL | | ##| timeopened | char(18) | YES | | NULL | | ##| timelastchanged | char(18) | YES | | NULL | | ##| mintuesopen | mediumint(8) unsigned | YES | | NULL | | ##| searchtermlist | varchar(255) | YES | | NULL | | ##+-----------------+-----------------------+------+-----+---------+-------+ attr_accessible :searchtermlist, :minutesopen, :timelastchanged, :tech end .... thisticket = Ticket.find_by_ticketid(ticketid) if thisticket != nil puts "---Ticket #{ticketid} Found!" if thisticket.searchtermlist.include? importedsearchtermlist puts "---Search term list current! Skipping..." else puts "---Updating search term list for ticket #{ticketid}" puts importedsearchtermlist puts thisticket.ticketid puts thisticket.searchtermlist updatedsearchtermlist = thisticket.searchtermlist &lt;&lt; "," &lt;&lt; importedsearchtermlist puts updatedsearchtermlist thisticket.searchtermlist = updatedsearchtermlist result = thisticket.save! puts result puts thisticket.changed? puts thisticket.searchtermlist sleep(60) end </code></pre> <p>And the output:</p> <pre><code>---Ticket 47048 Found! ---Updating search term list for ticket 47048 virus 47048 update update,virus true false update,virus </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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