Ruby on Rails Tutorial 学习笔记 --第七章 用户注册

1.Sass 的 mixin 功能

[ruby]  view plain copy
  1. @import "bootstrap";  
  2.   
  3. /* mixins, variables, etc. */  
  4.   
  5. $grayMediumLight#eaeaea;  
  6.   
  7. @mixin box_sizing {  
  8.   -moz-box-sizing: border-box;  
  9.   -webkit-box-sizing: border-box;  
  10.   box-sizing: border-box;  
  11. }  
  12. .  
  13. .  
  14. .  
  15.   
  16. /* miscellaneous */  
  17.   
  18. .debug_dump {  
  19.   clear: both;  
  20.   float: left;  
  21.   width: 100%;  
  22.   margin-top: 45px;  
  23.   @include box_sizing;  
  24. }  

2. REST 架构 : 把数据视为资源(resource),可以创建、显示、更新和删除,这四个操作分别对应了 HTTP 标准中的  POST GET PUT  和  DELETE  请求方法

3.params[:id] 会返回用户的 id

[ruby]  view plain copy
  1. class UsersController < ApplicationController  
  2.   
  3.   def show  
  4.     @user = User.find(params[:id])  
  5.   end  
  6.   
  7.   def new  
  8.   end  
  9. end  

4. let  方法

[ruby]  view plain copy
  1. <span style="font-weight: normal;"><span style="font-size:14px;">let(:found_user) { User.find_by_email(@user.email) }  
  2. #定义了一个名为 found_user 的变量,其值等于 find_by_email 的返回值。</span></span>  

5. 使用  form_for
[ruby]  view plain copy
  1. <% provide(:title'Sign up') %>  
  2. <h1>Sign up</h1>  
  3.   
  4. <div class="row">  
  5.   <div class="span6 offset3">  
  6.     <%= form_for(@userdo |f| %>  
  7.   
  8.       <%= f.label :name %>  
  9.       <%= f.text_field :name %>  
  10.   
  11.       <%= f.label :email %>  
  12.       <%= f.text_field :email %>  
  13.   
  14.       <%= f.label :password %>  
  15.       <%= f.password_field :password %>  
  16.   
  17.       <%= f.label :password_confirmation"Confirmation" %>  
  18.       <%= f.password_field :password_confirmation %>  
  19.   
  20.       <%= f.submit "Create my account"class"btn btn-large btn-primary" %>  
  21.     <% end %>  
  22.   </div>  
  23. </div>  

[ruby]  view plain copy
  1. <%= f.label :name %>  
  2. <%= f.text_field :name %>  
生成的 HTML 是
[ruby]  view plain copy
  1. <label for="user_name">Name</label>  
  2. <input id="user_name" name="user[name]" size="30" type="text" /

你可能感兴趣的:(Ruby on Rails Tutorial 学习笔记 --第七章 用户注册)