【Rails学习笔记】用户注册的流程
2013-10-07 16:43
495 查看
在网站布局中加入debug信息
<%= debug(params) if Rails.env.development? %>
添加 Gravatar 头像和侧边栏
然后需要我们自己去定义Gravatar方法
填写用户注册表单:
然后要分别对注册成功和失败两种情况进行测试
对应action代码如下:
<%= 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
相关文章推荐
- Ruby on Rails Tutorial 学习笔记 --第七章 用户注册
- Ruby on Rails Tutorial 学习笔记 --第九章 更新、显示和删除用户
- Ruby on Rails Tutorial 学习笔记 --第十章 用户的微博
- 【Rails学习笔记】用户微博【下】
- SharePoint【学习笔记】-- SharePoint 2010 启用Form认证并增加用户注册功能
- Ruby on Rails Tutorial 学习笔记 --第十一章关注用户
- 网络编程学习笔记二(实现一个基于简单TCP的用户注册程序)
- 【Rails学习笔记】更新、显示和删除用户(涉及分页)(上)
- 【Rails学习笔记】用户模型
- JAVA web 学习笔记三 向注册用户发送验邮件
- Android移动应用开发学习笔记(二)——用户注册
- 【Rails学习笔记】更新、显示和删除用户(涉及分页)(下)
- 【J2EE核心开发学习笔记 010】struts2的搭建及连接数据库实现用户注册与登录
- SpringMVC学习笔记(四)使用JSP处理表单(处理用户注册表单)
- 【django 学习笔记】13-会话、用户和注册
- 学习笔记(二)——单用户模式、救援模式、运行级别、启动流程、登录文件
- 【PHP学习笔记】用户注册模块用户类以及验证码类
- js学习入门教程笔记:css+html+js用户注册代码实现
- JSP学习笔记(三)-----使用JSP处理用户注册和登陆
- 学习笔记2-确认删除操作-动态添加元素、事件-用户注册界面