Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

controllers solution

  • Loading branch information...
commit f675467c2872bf8370bb42b34886c0f2a6ca2d0c 1 parent c6aa433
Chad Pytel authored
Showing with 110 additions and 42 deletions.
  1. +110 −42 podium/slides/railsconf-2010/_controllers.haml
152 podium/slides/railsconf-2010/_controllers.haml
View
@@ -12,32 +12,34 @@
.slide
- :rubycode
- class UserController < ApplicationController
- def login # doing double duty
- if request.post?
- if session[:user_id] = User.authenticate(params[:user][:login], params[:user][:password])
- flash[:message] = "Login successful"
- redirect_to root_url
- else
- flash[:warning] = "Login unsuccessful"
+ .small
+ :rubycode
+ class UserController < ApplicationController
+ def login # doing double duty
+ if request.post?
+ if session[:user_id] = User.authenticate(params[:user][:login], params[:user][:password])
+ flash[:message] = "Login successful"
+ redirect_to root_url
+ else
+ flash[:warning] = "Login unsuccessful"
+ end
end
end
- end
- def logout
- session[:user_id] = nil
- flash[:message] = 'Logged out'
- redirect_to :action => 'login'
- end
+ def logout
+ session[:user_id] = nil
+ flash[:message] = 'Logged out'
+ redirect_to :action => 'login'
+ end
- # RESTful actions...
- end
+ # RESTful actions...
+ end
.slide
-
- :rubycode
- map.resources :users, :collection => { :login => [:get, :post], :logout => :get }
+ .small
+ :rubycode
+ map.resources :users,
+ :collection => { :login => [:get, :post], :logout => :get }
.slide
@@ -49,35 +51,42 @@
.slide
- :rubycode
- class SessionsController < ApplicationController
- def new
- # Just render the sessions/new.html.erb template
- end
+ .small
+ :rubycode
+ class SessionsController < ApplicationController
+ def new
+ # Just render the sessions/new.html.erb template
+ end
- def create
- if session[:user_id] = User.authenticate(params[:user][:login], params[:user][:password])
- flash[:message] = "Login successful"
- redirect_to root_url
- else
- flash.now[:warning] = "Login unsuccessful"
- render :action => "new"
+ def create
+ if session[:user_id] = User.authenticate(params[:user][:login], params[:user][:password])
+ flash[:message] = "Login successful"
+ redirect_to root_url
+ else
+ flash.now[:warning] = "Login unsuccessful"
+ render :action => "new"
+ end
end
- end
- def destroy
- session[:user_id] = nil
- flash[:message] = 'Logged out'
- redirect_to login_url
+ def destroy
+ session[:user_id] = nil
+ flash[:message] = 'Logged out'
+ redirect_to login_url
+ end
end
- end
.slide
- :rubycode
- map.resource :sessions, :only => [:new, :create, :destroy]
- map.login "/login", :controller => :user_sessions, :action => :new
- map.logout "/logout", :controller => :user_sessions, :action => :destroy
+ .small
+ :rubycode
+ map.resource :sessions,
+ :only => [:new, :create, :destroy]
+ map.login "/login",
+ :controller => :user_sessions,
+ :action => :new
+ map.logout "/logout",
+ :controller => :user_sessions,
+ :action => :destroy
.slide
@@ -93,3 +102,62 @@
%h1 Solution
%h2 Extract to a New Controller
+
+.slide
+
+ %h2 Create the new flags controller
+ :code
+ script/generate controller flags
+
+.slide
+
+ %h2 Move Article flagging tests to flags_controller_test
+ .small
+ :rubycode
+ class FlagsControllerTest < ActionController::TestCase
+ test "should flag article" do
+ article = Factory(:article)
+ post :create, :article_id => article.to_param
+ assert_redirected_to article_path(article)
+ assert_equal "review", article.reload.state
+ end
+ end
+
+.slide
+
+ %h2 Move Article flagging code to FlagsController (and change)
+ .small
+ :rubycode
+ class FlagsController < ApplicationController
+ # POST /articles/1/flags
+ def create
+ article = Article.find(params[:article_id])
+ article.flag!
+ flash[:success] = "Article was successfully flagged"
+ redirect_to article_path(article)
+ end
+ end
+
+.slide
+
+ %h2 Setup new routes
+ :rubycode
+ map.resources :articles do |articles|
+ articles.resources :flags, :only => :create
+ end
+
+.slide
+
+ %h2 Change the View
+ .small
+ :htmlcode
+ <% content_for :sidebar do %>
+ <%= link_to 'Flag Article',
+ article_flags_path(@article),
+ :method => :post, :class => "orange" %>
+ <%= link_to 'Back', articles_path %>
+ <% end %>
+
+.slide
+
+ %h2 No Cucumber Tests Changed
Please sign in to comment.
Something went wrong with that request. Please try again.