Hi, How do I pass a variable from my action into a model before saving the model. I''d like the model instance to have access to this variable to do some work before saving the model instance but the variable is not part of the model itself. Thanks, Sam -- Posted via http://www.ruby-forum.com/.
On 7/28/06, Sam Donaldson <samonderous@gmail.com> wrote:> Hi, > > How do I pass a variable from my action into a model before saving the > model. I''d like the model instance to have access to this variable to > do some work before saving the model instance but the variable is not > part of the model itself.In your model class, put an attr_accessor :foo, then simply set it using e.g. model_obj.foo = 42 in your controller and access via foo in yout model. martin
Create a Model Object Suppose the Model''s name is form.rb in the controller, create an object for this model form_object = Form.new now assign an element to this object. form_object[''element1''] = "Hi this is the .............." now call the method in the model which is defined belw. form_object.validate_this in the model Form. ..... define a method like validate_this def validate_this puts "The variable is #{element1}" end now u can access this variable in this method Regards, Anand -- Posted via http://www.ruby-forum.com/.