ruby on rails - Pre-populate record with values from previous record -


I'm working in Ruby on the Railway app. I have a model that is user-made for many of them. Could.

When a user goes into a new action, I want to prepare those values ​​with values ​​from their last record. These can be changed if desired and used to create a new record.

I am convinced that in the new action of my controller, I can get the most recent record (using something like this).

  Model.first (: order = & Gt; "made_at DESC")  

Once I have that, I will use it with a new method How can I use to pre-populate the records created?

Can not you just start Atrial?

  class models & lt; ActiveRecord :: Base def initialize_some_attr Model.first (: order = & gt; "created_at DESC"). Some_attr end and  

Comments

Popular posts from this blog

paypal - How to know the URL referrer in PHP? -

oauth - Facebook OAuth2 Logout does not remove fb_ cookie -

wpf - Line breaks and indenting for the XAML of a saved FlowDocument? -