Posted By

andyh on 09/09/06


Tagged

rails ruby pattern


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

padraic
webstic


Single Record Save Action Pattern


 / Published in: Ruby
 

  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  

You need to login to post a comment.