Single Record Save Action Pattern


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. def single_record_action
  2. @record = params[:id] ? CustomRecord.find(params[:id]) : CustomRecord.new
  3. if request.post?
  4. @record.attributes = params[:record]
  5. begin
  6. @record.save!
  7. redirect_to :action=>'some_other_action'
  8. rescue ActiveRecord::RecordInvalid
  9. end
  10. end
  11. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.