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" /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值