1.Sass 的 mixin 功能
- @import "bootstrap";
- /* mixins, variables, etc. */
- $grayMediumLight: #eaeaea;
- @mixin box_sizing {
- -moz-box-sizing: border-box;
- -webkit-box-sizing: border-box;
- box-sizing: border-box;
- }
- .
- .
- .
- /* miscellaneous */
- .debug_dump {
- clear: both;
- float: left;
- width: 100%;
- margin-top: 45px;
- @include box_sizing;
- }
2. REST 架构 : 把数据视为资源(resource),可以创建、显示、更新和删除,这四个操作分别对应了 HTTP 标准中的
POST
、
GET
、
PUT
和
DELETE
请求方法
3.params[:id]
会返回用户的 id
- class UsersController < ApplicationController
- def show
- @user = User.find(params[:id])
- end
- def new
- end
- end
4.
let
方法
- <span style="font-weight: normal;"><span style="font-size:14px;">let(:found_user) { User.find_by_email(@user.email) }
- #定义了一个名为 found_user 的变量,其值等于 find_by_email 的返回值。</span></span>
- <span style="font-weight: normal;"><span style="font-size:14px;">let(:found_user) { User.find_by_email(@user.email) }
- #定义了一个名为 found_user 的变量,其值等于 find_by_email 的返回值。</span></span>
5.
使用
form_for
- <% provide(:title, 'Sign up') %>
- <h1>Sign up</h1>
- <div class="row">
- <div class="span6 offset3">
- <%= form_for(@user) do |f| %>
- <%= f.label :name %>
- <%= f.text_field :name %>
- <%= f.label :email %>
- <%= f.text_field :email %>
- <%= f.label :password %>
- <%= f.password_field :password %>
- <%= f.label :password_confirmation, "Confirmation" %>
- <%= f.password_field :password_confirmation %>
- <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
- <% end %>
- </div>
- </div>
- <%= f.label :name %>
- <%= f.text_field :name %>
- <label for="user_name">Name</label>
- <input id="user_name" name="user[name]" size="30" type="text" /