views:

22

answers:

1

Sorry, I think I am a bit stupid today

class Mutant < ActiveRecord::Base
  attr_accessible :style

  before_create :setup_values


  private

  def setup_values 
    style = "hardcore" unless style
  end
end

I like to call this stuff in the console like

Mutant.create(:style => "rampage") # expected is Mutant.first.style == "rampage"
Mutant.create # expected is Mutant.last.style == "hardcore but this doesn't work
A: 

just found it in the api

def setup_values 
  write_attribute :style, "hardcore" if style.blank?  
end

tadaa and it works :)

tabaluga
You wanted to use self.style = ... Doing just style = X, Ruby interprets that as a local variable, not a method call to #style=.
François Beausoleil