【Rails学习笔记】用户注册的流程
来源:互联网 发布:朗诵配乐知乎 编辑:程序博客网 时间:2024/06/09 21:19
在网站布局中加入debug信息
<%= debug(params) if Rails.env.development? %>
添加 Gravatar 头像和侧边栏
- <% provide(:title, @user.name) %>
- <h1>
- <%= gravatar_for @user %>
- <%= @user.name %>
- </h1>
然后需要我们自己去定义Gravatar方法
- module UsersHelper
- # Returns the Gravatar (http://gravatar.com/) for the given user.
- def gravatar_for(user)
- gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
- gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
- image_tag(gravatar_url, alt: user.name, class: "gravatar")
- end
- end
填写用户注册表单:
- <% 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>
然后要分别对注册成功和失败两种情况进行测试
- describe "signup" do
- before {visit signup_path}
- let(:submit) {"Create my account"}
- describe "with invalid information" do
- it "should not create a user" do
- expect {click_button submit}.not_to change(User, :count)
- end
- end
- describe "with valid information" do
- before do
- fill_in "Name", with: "Example User"
- fill_in "Email", with: "user@example.com"
- fill_in "Password", with: "foobar"
- fill_in "Confirmation", with: "foobar"
- end
- it "should create a user" do
- expect {click_button submit}.to change(User, :count).by(1)
- end
- end
- end
对应action代码如下:
- def create
- @user = User.new(user_params)
- if @user.save
- #
- flash[:success] = "Welcome to the Sample App!"
- redirect_to @user
- else
- render 'new'
- end
- end
0 0
- 【Rails学习笔记】用户注册的流程
- 【Rails学习笔记】用户注册的流程
- 【Rails学习笔记】用户模型
- 【Rails学习笔记】用户模型
- Ruby on Rails Tutorial 学习笔记 --第七章 用户注册
- 【Rails学习笔记】用户微博【上】
- 【Rails学习笔记】用户微博【下】
- 【Rails学习笔记】用户微博【下】
- 【Rails学习笔记】用户微博【上】
- Linux设备驱动程序学习笔记13:中断的注册流程
- Github用户注册流程
- 用户体验设计的基本流程(学习笔记)
- 【Rails学习笔记】用户与微博关联得到的方法
- Ruby on Rails Tutorial 学习笔记 --第十章 用户的微博
- 【Rails学习笔记】用户与微博关联得到的方法
- 【Rails学习笔记】用户关注功能(一)
- 【Rails学习笔记】用户关注功能(二)
- 【Rails学习笔记】用户关注功能(三)
- 小马哥----高仿小米 note刷机拆机主板图 2015新版机型 主板型号Q8 6582芯片 多图展示 警惕
- 自己动手写一个Struts2
- 工作流——JBPM4.4之HelloWorld示例
- 连线错误
- 央妈不会告诉你的房贷真相:欠银行钱越多越久才越好!
- 【Rails学习笔记】用户注册的流程
- 割点、桥、点双连通、边双连通、强连通 题目
- Cetos编译安装MySQL5.6
- 博客的测试
- 如何取消IE“已限制此网页运行可以访问计算机的脚本或ActiveX控件”
- vs的插件开发- VS开发设置VC项目调试命令
- Smali语法:Registers(寄存器)
- 【Rails学习笔记】用户模型
- win7 将tomcat添加到系统服务