public
Description: HomeMarks is a web based GUI to build HTML start pages.
Homepage: http://www.homemarks.com/
Clone URL: git://github.com/metaskills/homemarks.git
Click here to lend your support to: homemarks and make a donation at www.pledgie.com !
homemarks / lib / render_invalid_record.rb
100644 21 lines (15 sloc) 0.696 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module RenderInvalidRecord
  
  def self.included(base)
    base.rescue_from(ActiveRecord::RecordInvalid, :with => :render_invalid_record)
  end
  
  protected
  
  def render_invalid_record(exception)
    record = exception.record
    respond_to do |format|
      format.html { render :action => (record.new_record? ? 'new' : 'edit') }
      format.js { render :json => record.errors.full_messages, :status => :unprocessable_entity, :content_type => 'application/json' }
      format.xml { render :xml => record.errors.full_messages, :status => :unprocessable_entity }
      format.json { render :json => record.errors.full_messages, :status => :unprocessable_entity }
    end
  end
  
end