ruby on rails - Save in ActiveRecord -


When working with a model, when do you need to explicitly save? In a setter,

  def name = (n) self.name = n end  

should I save myself?

For your specific example, you will need to do something like this:

  Class MyClass & lt; ActiveRecord :: Base DF name = (n) save self.name = n! End of End  

I would like to save! Instead of saving, you do not plan to check the errors until you save! Will throw an exception, but the savings will fail silently.

BTW, I am guessing your example, is just an unrealistic fact, because you are overriding the existing activecord setter function for the "Name" field. The ActiveRecord Accessor method is quite different compared to simple Ruby Accessories, so if you create "name =" on the top of the automatically generated "name =" method, you get spoiled.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -