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

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

jQuery Ajax Render Fragments OR Whole Page -

java - Why is BlockingQueue.take() not releasing the thread? -