Displaying 3 results from an estimated 3 matches for "my_attribute".
2008 Dec 31
1
when to set a class attribute variable during boot
I have an ActiveRecord model with a cattr_accessor. The class
attribute is set up like this:
class MyModel < ActiveRecord::Base
cattr_accessor :my_attribute
end
Because I need to give #my_attribute environment-specific values, I
try to set this attribute in environments/development.rb like so:
MyModel.my_attribute = 3
But this leads to odd and erratic behavior when #my_attribute is
called from a controller. Sometimes MyModel.my_attribute returns 3,...
2006 Jul 14
3
override to_string for single attribute?
...for a single attribute
such that if the value is an integer, it displays with no decimal point
(e.g. "1"), but if it is non-integer, it displays with a decimal point
(e.g. "1.25").
The easiest way to do this seems to be if I could override the to_string
method for my_model.my_attribute.to_s. Is there a way to do this? Or
a better way altogether?
thanks,
Jeff
--
Posted via http://www.ruby-forum.com/.
2010 Apr 29
1
Setting a message on a model -without- errors.add_to_base
I''m trying my best to follow the skinny controller/fat model concept,
and I''ve got a series of callbacks (that I''m about to move into
observers) running on a few models. Based on what these callbacks do
to the data (it''s implementing business rules), I''d like to add some
type of message on the state of the model *without* invalidating it.
For example: