Hi All,
I've got a set of constraints in my model that work fine. I wanted to remove leading and trailing blanks in a :symbol entry if it is otherwise valid. So I added lines 9 & 10, as seen in the model class below. BTW, I tested those lines in a simple Ruby program (after declaring params = Hash.new) and theY worked fine for my purposes.
With the addition of lines 9 & 10, Rails reports: undefined local variable or method `params' and subsequently identifies line 10 as the offender.
I think I'm supposed to get the pamams from the session object. How can I do that in Rails 2.0.2?
I'm running Ruby 1.8.6 and Rails 2.0.2 over WinXP-Pro/SP2.
Thanks in advance, Richard
class Portfolio < ActiveRecord::Base before_save :uppercase_data
def uppercase_data self.symbol.upcase! end
validates_presence_of :symbol
params[:symbol] =~ /^\s*([A-Za-z0-9]*)\s*$/ # Line 10 params[:symbol] = $1 if $1 # Line 11
validates_format_of :symbol, :with => /^[a-zA-Z\d]+$/, :on => :create, :message => "(Character other than letter or digit found, e.g a blank)" validates_length_of :symbol, :maximum=>5, :message=>"exceeds %d characters" validates_uniqueness_of :symbol end