Ok, the solution was to not use #becomes and instead just set the type
field explicitly before saving.
//Linus
Den måndagen den 13:e maj 2013 kl. 10:19:08 UTC+2 skrev Linus
Pettersson:>
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/CGe2gD0XJwgJ.
For more options, visit https://groups.google.com/groups/opt_out.