Error Handling
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tasks
test
MIT-LICENSE
README
Rakefile
VERSION
init.rb
install.rb
uninstall.rb

README

ConcernedWith
=============

Simple way to separate model and controller concerns into separate files. Code is from Rick Olson's altered_beast project.


Example
=======

# app/models/user.rb
class User < ActiveRecord::Base
  concerned_with :validations, :authentication
end

# app/models/user/validations.rb
class User < ActiveRecord::Base
  validates_presence_of :name
end

#app/models/user/authentication.rb
class User < ActiveRecord::Base
  def self.authenticate(name, password)
    find_by_name_and_password(name, password)
  end
end

#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  concerned_with :authentication
end

#app/controllers/application/authentication.rb
class ApplicationController < ActionController::Base
  def logged_in?
    false
  end
end

Follow this one
=================================

Download and paste in plugin

#app/controllers/application_controller.rb
concerned_with :rescues

#app/controllers/application/rescues.rb
class ApplicationController < ActionController::Base
  rescue_from   ActionController::RoutingError , :with => :route_not_found
  rescue_from  ActiveRecord::RecordNotFound, :with => :record_not_found

  protected
  def route_not_found
    redirect_to root_path
  end

  def record_not_found
    redirect_to root_path
  end

end