12: Following Users in Java

Generator DataMatrix in Java 12: Following Users
12: Following Users
Encode Data Matrix 2d Barcode In Java
Using Barcode maker for Java Control to generate, create DataMatrix image in Java applications.
before(:each) do @user = test_sign_in(Factory(:user)) @other_user = Factory(:user, :email => Factorynext(:email)) @userfollow!(@other_user) end it "should show user following" do get :following, :id => @user responseshould have_selector("a", :href => user_path(@other_user), :content => @other_username) end it "should show user followers" do get :followers, :id => @other_user responseshould have_selector("a", :href => user_path(@user), :content => @username) end end end end
Bar Code Generation In Java
Using Barcode maker for Java Control to generate, create bar code image in Java applications.
The only tricky part of the implementation is realizing that we need to add two new actions to the Users controller; based on the routes defined in Listing 1219, we need to call them following and followers Each action needs to set a title, find the user, retrieve either @userfollowing or @userfollowers (in paginated form), and then render the page The result appears in Listing 1229
Recognize Bar Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
A Web Interface for Following and Followers
Generate Data Matrix In Visual C#.NET
Using Barcode drawer for .NET Control to generate, create Data Matrix image in .NET applications.
Listing 1229 The following and followers actions
Drawing DataMatrix In .NET
Using Barcode printer for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications.
app/controllers/users_controllerrb
Data Matrix 2d Barcode Encoder In Visual Studio .NET
Using Barcode creator for VS .NET Control to generate, create DataMatrix image in .NET applications.
class UsersController < ApplicationController before_filter :authenticate, :except => [:show, :new, :create] def following @title = "Following" @user = Userfind(params[:id]) @users = @userfollowingpaginate(:page => params[:page]) render 'show_follow' end def followers @title = "Followers" @user = Userfind(params[:id]) @users = @userfollowerspaginate(:page => params[:page]) render 'show_follow' end end
Generate ECC200 In VB.NET
Using Barcode printer for VS .NET Control to generate, create Data Matrix image in Visual Studio .NET applications.
Note here that both actions make an explicit call to render, in this case rendering a view called show_follow, which we must create The reason for the common view is that the ERb is nearly identical for the two cases, and Listing 1230 covers them both
Draw Barcode In Java
Using Barcode maker for Java Control to generate, create barcode image in Java applications.
Listing 1230 The show_follow view used to render following and followers
Create Bar Code In Java
Using Barcode printer for Java Control to generate, create barcode image in Java applications.
app/views/users/show_followhtmlerb
Drawing Code 39 In Java
Using Barcode encoder for Java Control to generate, create USS Code 39 image in Java applications.
<table summary="Information about following/followers"> <tr> <td class="main"> <h1><%= @title %></h1> <% unless @usersempty %> <ul class="users"> <%= render @users %> </ul> <%= will_paginate @users %> <% end %> </td>
Code 128 Code Set B Generator In Java
Using Barcode printer for Java Control to generate, create Code 128C image in Java applications.
12: Following Users
Printing GTIN - 12 In Java
Using Barcode printer for Java Control to generate, create GTIN - 12 image in Java applications.
<td class="sidebar round"> <strong>Name</strong> <%= @username %><br /> <strong>URL</strong> <%= link_to user_path(@user), @user %><br /> <strong>Microposts</strong> <%= @usermicropostscount %> <%= render 'shared/stats' %> <% unless @usersempty %> <% @userseach do |user| %> <%= link_to gravatar_for(user, :size => 30), user %> <% end %> <% end %> </td> </tr> </table>
RoyalMail4SCC Printer In Java
Using Barcode generation for Java Control to generate, create Royal Mail Barcode image in Java applications.
There s a second detail in Listing 1229 worth noting: in order to protect the pages for following and followers from unauthorized access, we have changed the authentication before filter to use :except instead of :only So far in this tutorial, we have used :only to indicate which actions the filter gets applied to; with the addition of the new protected actions, the balance has shifted, and it is simpler to indicate which actions shouldn t be filtered We do this with the :except option to the authenticate before filter:
Scan Data Matrix In .NET
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
before_filter :authenticate, :except => [:show, :new, :create]
Encode Barcode In C#.NET
Using Barcode generation for .NET framework Control to generate, create barcode image in .NET framework applications.
With that, the tests should now be passing, and the pages should render as shown in Figure 1216 (following) and Figure 1217 (followers) You might note that, even with the common show_followers partial, the following and followers actions still have a lot of duplication Moreover, the show_followers partial itself shares common features with the user show page Section 125 includes exercises to eliminate these sources of duplication
Encoding GS1 - 13 In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create GS1 - 13 image in ASP.NET applications.
1224 A Working Follow Button the Standard Way
DataMatrix Generation In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create Data Matrix image in ASP.NET applications.
Now that our views are in order, it s time to get the follow/unfollow buttons working Since following a user creates a relationship, and unfollowing a user destroys a relationship, this involves writing the create and destroy actions for the Relationships controller Naturally, both actions should be protected; for signed-in users, we will use the follow! and unfollow! utility methods defined in Section 1214 to create and destroy the relevant relationships These requirements lead to the tests in Listing 1231
Generate UPC A In .NET
Using Barcode generator for .NET framework Control to generate, create GTIN - 12 image in VS .NET applications.
A Web Interface for Following and Followers
UCC-128 Encoder In .NET
Using Barcode generator for .NET Control to generate, create GTIN - 128 image in Visual Studio .NET applications.
Showing the users being followed by the current user
Code 128 Code Set B Generation In Visual Basic .NET
Using Barcode creator for Visual Studio .NET Control to generate, create Code 128 image in .NET applications.
Listing 1231 Tests for the Relationships controller actions
spec/controllers/relationships_controller_specrb
require 'spec_helper' describe RelationshipsController do describe "access control" do it "should require signin for create" do post :create responseshould redirect_to(signin_path) end it "should require signin for destroy" do delete :destroy, :id => 1 responseshould redirect_to(signin_path) end end
describe "POST 'create'" do
12: Following Users
before(:each) do @user = test_sign_in(Factory(:user)) @followed = Factory(:user, :email => Factorynext(:email)) end it "should create a relationship" do lambda do post :create, :relationship => { :followed_id => @followed } responseshould be_redirect endshould change(Relationship, :count)by(1) end end describe "DELETE 'destroy'" do before(:each) do @user = test_sign_in(Factory(:user)) @followed = Factory(:user, :email => Factorynext(:email)) @userfollow!(@followed) @relationship = @userrelationshipsfind_by_followed_id(@followed) end it "should destroy a relationship" do lambda do delete :destroy, :id => @relationship responseshould be_redirect endshould change(Relationship, :count)by(-1) end end end