Cannot change attribute with self[:attribute]= or write_attribute(:attribute, value)


I have a model called Vocab with an integer variable named box. I
defined a method named promote which increases box by one:

def promote
  self[:box] += 1

I put a link in the list.rhtml view created by scaffold

<% for vocab in @vocabs %>
<td><%= link_to 'Promote', :action => 'promote', :id => vocab %></td>

and created a promote message in the controller, which passes it on to
the model

def promote
  @vocab = Vocab.find(params[:id])
  redirect_to :action => 'list'

However, this isn't working; the box variable stays the same. Changing
the model's method to

def promote
  value_before = self[:box]
  self[:box] += 1
  value_after = self[:box]
  logger.error "Oops! First, box was #{value_before} and now it's

produces this in development.log:

Oops! First, box was 4 and now it's 5.

So the variable box does change, but the database entry probably
hasn't been updated. I also tried write_attribute, but no luck. What
am I doing wrong?


ah yes, that did the trick. Thanks!

I also realized that self[:box] is unnecessary, since I'm not
overwriting any readers or writers.