using .becomes(class) on STI models prevents attachment from being saves

1 view
Skip to first unread message

Spike

unread,
Jul 21, 2009, 12:25:51 AM7/21/09
to Paperclip Plugin
Hi there, quite an edge case, but I have a STI set of models (quiz
questions). The attachment is defined on the parent class.

If you do this:

@question = @quiz.questions.build(params[:question]).becomes(params
[:question][:question_type].constantize)

it will still save the file details to the database but won't actually
save the file.

To work around it you just build the question and then set the
attributes later:

@question = @quiz.questions.build.becomes(params[:question]
[:question_type].constantize)
@question.attributes = params[:quiz_set_quiz_question]

but it's be nice if it actually worked. I presume paperclip is loosing
track of the file during the class changing process.

Cheers,

Brendon
Reply all
Reply to author
Forward
0 new messages