Skip to content

Instantly share code, notes, and snippets.

@moretea
Created January 24, 2012 09:03
Show Gist options
  • Select an option

  • Save moretea/1668990 to your computer and use it in GitHub Desktop.

Select an option

Save moretea/1668990 to your computer and use it in GitHub Desktop.
# routes.rb
TestApp::Application.routes.draw do
resources :logins
resource :session
resources :accounts do
resources :things
end
end
# action_controller.rb
class ApplicationController < ActionController::Base
include LoginHelper # Force it to be present in all controllers
end
# login_helper.rb
module LoginHelper
def current_login
@current_login ||= Login.find_by_id(session[:login_id])
end
def logged_in?
current_login.present?
end
end
#things_controller.rb
class ThingsController < ApplicationController
before_filter :find_account
def find_account
@account = Account.find(params[:account_id])
end
def index
@things = @account.things
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment