/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def multiple_record_action if params[:id] @record = CustomRecord.find(params[:id]) @dependent = @record.dependent else @record = CustomRecord.new @dependent = Dependent.new @dependent.record = @record end if request.post? @record.attributes = params[:record] @dependent.attributes = params[:dependent] begin @record.transaction(@record, @dependent) do @record.save @record.reload unless @record.id @dependent.save raise ActiveRecord::RecordInvalid unless @record.valid? && @dependent.valid? redirect_to :action=>'some_other_action' end rescue ActiveRecord::RecordInvalid end end end