I want to alter the data and save it then to the database when using the new / create function of the app.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should use active callbacks, as the two other answers stated. The *before_create* is definitely the one you are looking for. Always do that kind of logic in the model, and not in the controller. Rails mantra (one of many) is “thin controller, fat model”, which enable code reuse more easily.
You can check the active callbacks documentation at :
http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
Also, here is an example of what you want to achieve