Sign in through GitHub

RailsCasts Pro episodes are now free!

Learn more or hide this

Daniel Loureiro's Profile

GitHub User: loureirorg

Site: http://fanzine.com.br

Comments by Daniel Loureiro

Avatar

to avoid the readonly error, use "reset_counters" instead of "update_attribute":

ruby
Project.reset_column_information
Project.all.find_each do |p|
  Project.reset_counters p.id, :tasks
end
Avatar

This doesn't work anymore in Rails 4.2. Instead, use rescue_from.

Example:

ruby
class ApplicationController < ActionController::Base
  rescue_from User::NotAuthorized, with: :deny_access # self defined exception
  rescue_from ActiveRecord::RecordInvalid, with: :show_errors

  rescue_from 'MyAppError::Base' do |exception|
    render xml: exception, status: 500
  end

  protected
    def deny_access
      ...
    end

    def show_errors(exception)
      exception.record.new_record? ? ...
    end
end