[Rails] STI convert object to other object
Hi
I'm using STI and want to convert one object to the other. The reason to why I'm using STI is that I have a report and a full report. First someone reports something and can only enter a few fields. Then and admin can convert this into a full report and fill out the full report. Using STI makes it easier to handle the views, validations etc.
When converting it I just go to the edit action of a full_report, fetch the report and converts it into a full report using the #becomes(FullReport) method. The issue is when I submit this form and I want to save it in the update action I do this:
@report = Report.find(params[:id])
@report = @report.becomes(FullReport) if @report.type.nil?
if @report.update_attributes(report_params) ....
....
The thing is that it doesn't save the type as FullReport when I do this.
Why is that? I can't convert it, save it, reload and update it since the validations will fail.
So, how can I convert the object and update its attributes at the same time?
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/e2E86JnP4LoJ.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home