`
peryt
  • 浏览: 54347 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论
  • waiting: 既然都指定了dataType为'script'那就不必特别在b ...
    jQuery
文章列表
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 allow user to sign in, we need to find the user record corresponding to the submitted email address. ...
using validates :email, :uniqueness => true    doesn't guarantee uniqueness!!!!!   here is why:   1. Alice sign up with address alice@wonderland.com 2. Alice accidentally clicks on "Submit" twice, sending two requests in quick succession. 3. the following sequence occurs:  reques ...
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 it will load the data with no waiting.)   cars = Car.find(1) cars = Car.find(p ...
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 pressences, length, unique, format, and add confirmation.   3. we will continue to use test-driven dev.   ...
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: --sandbox this param make sure when you exit the console, all changes made here will be rolled back!!!   rails console --sandbox   (if you want to pla ...
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 controller Users new but when gen model, we use singular:   rails g model User name:string email:strin ...
1. the purpose of rails routes:   a. recognize url, and dispatch to correct controller and actions b. generate named routes, i.e. paths and urls, so the you needn't hardcode them in views   2. the simpleset route:   when rails receive a incoming request,    GET /patients/17   it will ask t ...
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 "users/new"   2. next, we will start another loop of test-driven development:   first, we ...
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 home page "/home", "/about", you will need integration test, integration test can t ...
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">About</a>   but it works, but this is not rails way   a. it will disclose & ...
in last chapters, we find the layout file is getting much more clutterred.   partials in rails are very useful to clear this clutter in views.   1. we will move the stylesheets include part into a partial 2. we will move the header part into a partial.   below is the new code:     <!DOCT ...

add css

1. the images need to go to public/images dir.   2. the comments in css file: /* ...............*/   3. see the example css below, we will explain one by one:   .container { width: 710px; } body { background: #cff; } header { padding-top: 20px; } header img { padding: 1 ...
continue with the prior article, I'll try to add a sign up link to our home page.     <%= link_to "Sign up now!", '#', :class => "signup_button round" %> Remember, # means a blank link, a link to itself.    the generated html will be:   <a href="#" cl ...
First, let's see a sample layout file in rails, and explain it step by step:     <!DOCTYPE html> <html> <head> <title><%= title %></title> <%= csrf_meta_tag %> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode ...
  1.  class Word    def palindrome?(string)        string == string.reverse    endend  in this class, it doesn't indicate superclass explicitly, so the default is inherit from Object class.   since it doesn't define initialize method, it will use the initialize method of Object class.   how to ...
Global site tag (gtag.js) - Google Analytics