本文主要是介绍Ruby学习笔记7: 添加身份验证(adding Authentication),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我们已经完成了Category & Product页面内容的增删改查,再加入一个身份验证即可成为一个较完整的Rails App了。本文就来完成这个任务。
We now need to give users the ability to sign up for the app so that they can do things like purchase products or leave reviews.
To do this, we'll add a user authentication system to the app.看下图:
1. install a gem called Devise.
Earlier, we learned about bundler and how it sets up our gems. To add authentication, we'll install a gem called Devise.
We've gone ahead and added Devise for you in your Gemfile. Run bundle to install it in your app.
bundle install
to update all your gems. Press Enter.
这个命令看起来好像是依托于一个叫做GemFile的文件的:
source 'https://rubygems.org'# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '1.3.9'
# Use SCSS for stylesheets
gem 'sass-rails', '4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :rubygem 'paperclip', '4.2.0'# Use jquery as the JavaScript library
gem 'jquery-rails', '3.1.2'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '2.4.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '2.2.2'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '0.4.0', group: :doc# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', '1.1.3', group: :development# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'# Use unicorn as the app server
# gem 'unicorn'# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development# Use
这篇关于Ruby学习笔记7: 添加身份验证(adding Authentication)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!