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
h1, #topHeadline, p.bigheader { | |
color: red; | |
font-size: 125%; | |
text-align: center; | |
border: 1px solid #d0d0c0; | |
} |
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
Feature: User can search for a movie (vague) | |
Feature: User can search for a movie by title (specific) |
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
# Run 'rails generate migration create_reviews' and then | |
# edit db/migrate/*_create_reviews.rb to look like this: | |
class CreateReviews < ActiveRecord::Migration | |
def up | |
create_table 'reviews' do |t| | |
t.integer 'potatoes' | |
t.text 'comments' | |
t.references 'moviegoer' | |
t.references 'movie' | |
end |
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
class ApplicationController < ActionController::Base | |
before_filter :set_current_user | |
protected # prevents method from being invoked by a route | |
def set_current_user | |
# we exploit the fact that find_by_id(nil) returns nil | |
@current_user ||= Moviegoer.find_by_id(session[:user_id]) | |
redirect_to login_path and return unless @current_user | |
end | |
end |
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
#login | |
- if @current_user | |
%p.welcome Welcome, #{@current_user.name}! | |
= link_to 'Log Out', logout_path | |
- else | |
%p.login= link_to 'Log in with your Twitter account', '/auth/twitter' |
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
get 'auth/:provider/callback' => 'sessions#create' | |
post 'logout' => 'sessions#destroy' | |
get 'auth/failure' => 'sessions#failure' |
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
class SessionsController < ApplicationController | |
# user shouldn't have to be logged in before logging in! | |
skip_before_filter :set_current_user | |
def create | |
auth=request.env["omniauth.auth"] | |
user=Moviegoer.find_by_provider_and_uid(auth["provider"],auth["uid"]) || | |
Moviegoer.create_with_omniauth(auth) | |
session[:user_id] = user.id | |
redirect_to movies_path | |
end |
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
# somewhat contrived example of an around-filter | |
around_filter :only => ['withdraw_money', 'transfer_money'] do | |
# log who is trying to move money around | |
start = Time.now | |
yield # do the action | |
# note how long it took | |
logger.info params | |
logger.info (Time.now - start) | |
end |
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
class UsersController < ApplicationController | |
before_filter :logged_in?, :except => [:login, :process_login] | |
private # subsequent methods are private to this class, until 'public' given | |
def logged_in? | |
redirect_to login_path and return unless | |
(@current_user = get_logged_in_user) | |
end | |
public | |
# ...controller actions go here | |
end |
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
# replaces the 'create' method in controller: | |
def create | |
@movie = Movie.new(params[:movie]) | |
if @movie.save | |
flash[:notice] = "#{@movie.title} was successfully created." | |
redirect_to movies_path | |
else | |
render 'new' # note, 'new' template can access @movie's field values! | |
end | |
end |
OlderNewer