If I have a Model called ‘templates’ with fields ‘a,b,c,d,e,f,g’ and I have a “reports’ model with unique fields but also the same fields that ‘templates’ has: ‘blue,red,gold,green,a,b,c,d,e,f,g’).
Say on the form for a new Report, there’s a drop list to pick a template and the value of that list will be a template id. So, in the create action for Reports, I create a new Report object and then find the selected template by id.
@report = Report.new(params[:report])
@template = find(params[:report][:template_id])
At this point (considering that the @report object includes all the fields the @template object does), is there a consise way of copying the values of @template into the @report object?
Thanks!
Rails 2.3.5 / Ruby 1.8.7
Simplest way: