Extend model.save method Rails -


can take .save method of activerecord models , add functionality it? use of attributes of item being saved in function

can like?

class item < activerecord::base     def self.save         <added stuff save>         <including some_other_id_from_this_item>     end end 

or break things? , how access this_item.the_column_i_need?

you should use activerecords callbacks extend behavior of save.

with before_save hook can access data before record saved, example change case of entered email can like

class user < activerecord::base   before_save :downcase_email    def downcase_email     email.downcase!   end end 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -