Created
January 24, 2012 09:03
-
-
Save moretea/1668990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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