- 博客(68)
- 收藏
- 关注
原创 12.3.3 scaling issue of the status feed
the problem of the implementation of last chapter is: 1. it has a line of code: following_ids = user.following_idsthis will fetch all the followed users of this user, but what we need to...
2011-10-30 17:54:05 129
原创 12.3 the status feed
1. we need to get all the micropost of the users followed by current user. Micropost.from_users_followed_by(user) so we can write a test this method. describe Micropost do . . . ...
2011-10-30 15:34:16 158
原创 12.2 a working follow button with Ajax
1. in the last chapter, in the user profile screen, the user can click on the follow button, then he is redirect back to the original profile screen. so we can ask, why do we leave that profile ...
2011-10-29 18:10:06 115
原创 12.2 a web interface for following and followers.
1.before we do the UI, we need to populate database.we will write a rake task to do this: namespace :db do desc "populate database" task :populate => :environment do Rake:Task["...
2011-10-28 22:14:32 380
原创 12. following user, 12.1 relationship model
1. we need to use a relationships table to stand for the following relationship: has_many :following, :through => :relationships, :source => "followed_id" 2. then $ rails generate m...
2011-10-18 14:29:00 175
原创 11.3 manipulating microposts.
1. since all micropost actions will be done in users page, so we only need :create and :destroy actions. so the routes will be: resources :microposts, :only => [:create, :destroy] 2...
2011-10-17 15:31:24 195
原创 11.2 show microposts.
1. add test to test the new users/show view: describe UsersController do render_views . describe "GET 'show'" do before(:each) do @user = Factory(:user) end . . ...
2011-10-17 12:01:38 104
原创 11.1 user micropost -- a micropost model.
1. we will first generate a micropost model. $ rails generate model Micropost content:string user_id:integer note, if you the content is longer, you can use type "text" instead of string ...
2011-10-17 10:43:52 166
原创 10.4 destroying users.
in this chapter, we will add destroy action to users controller to finish REST. first, we need to add administrative users who can use the destroy action. so we need to add a new attr of admin whi...
2011-10-16 15:47:05 124
原创 10.3 showing users list
in this chapter, we will do user list, i.e. the index action of users controller.at the same time, we will study pagination, and how to populate many sample data into database. 1. we will make s...
2011-10-15 20:41:57 122
原创 10.2 protect pages.
again, we will start from TDD!!! 1. since both edit and update need the same authentication, we can put their test together: describe "authentication of edit/update pages" do befor...
2011-10-15 15:11:46 109
原创 10.1 updating users.
1. git checkout -b updating-users 2. in this chapter, we will make you can update user profile.a. we will use a "edit" action to render a view to edit user.b. we will use "update" action and a...
2011-10-14 18:30:01 130
原创 9.4 sign out
whew!!!, last chapter is a long one! now, we are going to implement sign out. 1. no wonders, we will start from TDD. describe "DELETE 'destroy'" do it "should sign a user out" do t...
2011-10-13 15:21:13 181
原创 9.3 sign in success.
1. we will first finish the create action: def create user = User.authenticate(params[:session][:email], params[:session][:password]) if user.nil? fl...
2011-10-12 15:39:20 238
原创 9.1 about flash.now[:error] vs flash[:error]
There’s a subtle difference between flash and flash.now. The flash variable is designed to be used before a redirect, and it persists on the resulting page for one request—that is, it appears once...
2011-10-12 15:37:58 104
原创 9.2 sign in failure
start from TDD!!! 1. require 'spec_helper'describe SessionsController do render_views . . . describe "POST 'create'" do describe "invalid signin" do before(:each) ...
2011-10-12 12:19:30 216
原创 9.1 sessions
a session is a semi-permanent connection between 2 computers, such as client running browser & server running rails. there are several model for session behaviors:1. forget session on browse...
2011-10-12 10:00:52 94
原创 8 what test framework should you use?
for integration test, i have no prefer between the default Test:Unit and Rspec. just stick to one framework inside a project, no need to mix the two in one project. A second option is Cu...
2011-10-12 10:00:14 95
原创 8.4 rspec integration tests
in integration test, you can test many controllers at the same time, test a complete workflow, like login to the home page, open signup page, fill in contents, and submit...... maybe you have ...
2011-10-11 16:53:43 80
原创 8.3 sign up success
Chapter 8.3this part, we will deal with the case that sign up success. 1. start from TDD!!!! describe "success" do before(:each) do @attr = { :name => "New User", :em...
2011-10-11 14:39:49 206
原创 8.2 sign up failure
chapter 8.2 for this section, we will do this: if a signup form has invalid submission, the app will re-render the signup page, show the error details. 1. we will do TDD again!!! resou...
2011-10-11 11:59:54 249
原创 understand rails authenticity Token!
What happens: When the user views a form to create, update, or destroy a resource, the rails app would create a random authenticity_token, store this token in the session, and place it in a hidden f...
2011-10-11 11:24:26 85
原创 8.1 sign up form
chapter 8.1 1. let's first make a branch for the sign up chapter:git checkout -b signing-up 2. also reset the database:rake db:reset 3. we already got two basic test for new action in ...
2011-10-11 11:17:15 333
原创 7.3 better user views
Chapter 7.3 now, we have a good user model, we can try to make a show page to show the user info. we already have some test for the new action in the users controller. now we will add some...
2011-10-10 16:43:36 84
原创 write a authenticate method
chapter 7.2.4 1. we need to create a user, save it to database2. we need to get the user object by email3. we need to verify that it has a given password not surprising, we will start from...
2011-10-10 16:18:10 186
原创 7.2 secure the password
chapter 7.2 again, let's start from TDD again!!!!!!!!!!!!!! 1. since we define the encrypt_password into private area, how do we test it???????? ok, we need some public interface to use it...
2011-10-10 12:20:19 108
原创 7.1.3 active record callback
chapter 7.1.3 now that our user model has an attr for storing password, we need to arrange to generate and save an encrypted password when save user to the database. the technique of doing thi...
2011-10-10 11:47:30 75
原创 7.1 adding passwords to user model.
1. rake db:reset this command is very useful, it will clear the old sample data from database, so we again have a clean database 2. here, we will just use plain password, with bad secure, we w...
2011-10-09 14:44:15 177
原创 6.3 make model, view, controller work together.
1. let's start to console without --sandbox param to create some record into our database: rails consoleUser.create!(:name => "china zhang", :email => "china@china.com") to see if t...
2011-10-09 10:20:02 4622
原创 6.3 add some debug info to the layouts, rails environment.
<html> <body> <div class="container"> <%= render 'layouts/footer'%> <%= debug(params) if Rails.env.development? %> </div> <
2011-10-08 18:29:45 73
6.2 a tip when creating a column in a database
it is important to consider if we will need to find records by that column, the we decide if we need to set index on this column!!!!!!!!!!!!!!! consider, for example, the email attribute, when we ...
2011-10-08 16:34:08 54
6.2 the uniqueness caveat when saving into database: adding index to tables!!!
using validates :email, :uniqueness => true doesn't guarantee uniqueness!!!!! here is why: 1. Alice sign up with address alice@wonderland.com2. Alice accidentally clicks on "Submit" ...
2011-10-08 16:25:02 97
开发学到的东西
1.options = User.all(:conditions => "status <> 3", :order => "firstname, lastname").collect{|x| [x.name, x.id.to_s]} cars = Car.where(:colour => 'black').all (adding .all means ...
2011-09-26 17:28:47 82
原创 6.2 user validations
1. ok, let's add validations to our models:a. name should not be blank.b. email should follow email format.c. email should be unique. 2. there are some common validations:validates pressen...
2011-09-13 18:31:58 271
6.1 play with the newly created model.
in prev chapter, we created a user model, now we will play with it. 1. first, let's start rails console, this time we will use a param: --sandboxthis param make sure when you exit the cons...
2011-09-05 12:26:35 112
6.1 adding models and migrate to database in rails
1. now, we will add User model to our app, so that we can register, sign in, etc. rails g model User name:string email:string note:when generate controller, we use plural format: rails g co...
2011-09-05 11:39:41 52
5.2 rails routes
1. the purpose of rails routes: a. recognize url, and dispatch to correct controller and actionsb. generate named routes, i.e. paths and urls, so the you needn't hardcode them in views 2. th...
2011-09-03 10:20:10 108
5.3 create a controller for users to register our site.
1. rails generate controller Users new this line of code will generate a users controller and a new action, also a spec test file of users_controller_spec.rb and also a route get "u...
2011-09-02 18:48:01 74
5.2 integration test using rspec.
in this chapter,we will see a very simple integration test to test routes in rails. controller test is only able to test routes inside the controller, so if you want to test global routes, like ho...
2011-09-01 09:21:00 77
routes, add links to views
this chapter is very simple. in previous chapters, we just use "#" as the url in the links. now we will fill with actual link urls 1. we can hard code to:<a href="pages/about">Abou...
2011-08-31 10:02:06 118
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人