I have been using RoRfor a few days, so excuse me if this is a basic
question.
I am trying to save a model object from an action in a controller.
When I call a method on the model object that causes a state change,
then call save, no sql is generated.
However, if I modify the model object property directly from the
controller, then call save, sql is generated.
Here is an example of what I am talking about:
Model object
-----------------
class MyClass < ActiveRecord::Base
def modifyModel
aDate = Date.today
end
end
Controller
-------------
# this method generates a sql update
def method1
@myClass = MyClass.find(params[:id])
@myClass.aDate = Date.today
@budget_entry.save!
<...rest of code omitted...>
end
# this method does not generate a sql update
def method2
@myClass = MyClass.find(params[:id])
@myClass.modifyModel
@budget_entry.save!
<...rest of code omitted...>
end
Can someone please steer me in the right direction? I want to
encapsulate the state change to certain methods of the model.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---