rails使用devise做登录验证

左手 posted @ 2013年12月12日 20:28 in 积累点滴 with tags devise devise添加用户名 devise添加管理员 rails devise , 4845 阅读

使用devise这个gem只需要简单几步就能做好用户注册登录等功能,能节省大量时间和精力。

1. 安装devise
# 编辑Gemfile加入以下内容
gem 'devise'
#安装gem
bundle install
#初始化devise
rails g devise:install
#初始化model为user
rails g devise user
#初始化视图
rails g devise:views
# 创建数据库
rake db:migrate

2. 使用
# 创建一个空的controller
rails g controller home index --no-helper --no-assets
# 编辑config/routes.rb将home index设为首页
root 'home#index'
# 编辑app/views/home/index.html.erb加入以下内容

<h1>Home#index</h1>
<% if user_signed_in? %>
  hello, <%= current_user.username %><br />
  <%= link_to('登出', destroy_user_session_path, :method => :delete) %>
<% else %>
  <%= link_to('注册', new_registration_path(:user)) %>
  <%= link_to('登录', new_session_path(:user)) %>
<% end %>

此时访问http://localhost:3000就可以使用注册登录功能了。
另附两个有用到的链接:
1. 添加用户名登录 How To: Allow users to sign in using their username or email address
2. 添加管理员角色 How To: Add an Admin Role

Avatar_small
maid services dubai 说:
2019年9月17日 21:54

Earlier than jumping into the house maintenance services company’s guidance, let my family suggest that you a fun option to exercise and put some money aside all at once! A investigation indicated that your particular regular unique could lose 200 that will 260 calories per hour doing house cleaning! So, let’s start the main tip meant for saving by just doing most of the houses maintenance alone, and lose some calories as the reward!

Avatar_small
I sell pittsburgh ho 说:
2019年11月14日 02:49

It consultants use business clients to enhance the it department within an organization. Consultants aid companies within the implementation associated with new technology within the organization.

Avatar_small
pr home school 说:
2020年3月21日 22:03

Begin by thinking about your. Are you in a position to buy a residence? How much on earth do you afford at a monthly loan payment? How a good deal space do you really want? What patches of town you like? When you have answer a lot of these questions, get a "To Do" list as well as begin doing simple research around property. Talk to good friends, drive because of neighborhoods, and check out in that "Homes" element of the journal, Foreclosure Listing, and search.

Avatar_small
mv home inspections 说:
2020年3月21日 22:04

Your home inspection, mainly because defined, is definitely examination within the physical system and systems associated with a home, which is designed with a detailed 'snapshot' of the healthiness of the home when the test. The reasons like a your home inspection is in reducing some within the risk needed for purchasing your home; however, it all cannot reduce those problems, nor will the inspector prepare for future gatherings or shifts in performance as a consequence of changes active or occupancy.

Avatar_small
uk cleaning director 说:
2020年3月21日 22:04

Almost everyone can like the comfort to a clean and even well preserved home. Home cleaning is known as a necessity several people want to keep their property cleans because of their chaotic schedules. Homes should really be cleaned regularly that allows unpleasant odours and vermin infestations to remain prevented.

Avatar_small
part time maids in d 说:
2020年4月29日 18:01

After this you prepare a summary of your anticipation on what you need her to complete. You should ask ahead of time about the actual rates with regard to various work or cleansing services as well as whether you'll need any proprietor insurance. Find out do you know the tax significance if you will hire the independent cleaning service on agreement basis.

Avatar_small
painting services in 说:
2020年4月29日 18:01

Mentionened above previously, you might have a expert house plumber paint your home or you might get the job done yourself. Should you intend on doing the work yourself, then you will surely low cost, which might otherwise double for having to pay contractors and also the labor carried out. Since you're working on your personal, there tend to be some required fundamentals that you ought to be acquainted with, when it involves painting the inside of your house.

Avatar_small
dial a maid dubai 说:
2021年6月07日 14:27

Without having a proper house cleaning plan, it takes all his time to cover the total house. Not to mention, the vacuuming experts from any house cleaning service bureaus always have a strategic cleaning plan to accomplish the total procedure at all time potential. So, make a subscriber base and straighten out the necessary ingredients that are would have to be done.

Avatar_small
BSE Odisha Question 说:
2022年9月03日 15:38

Odisha 10th Previous Question Paper 2023 Download Students who have Started their Preparation for the Exam can also in the Pdf File Format, Whenever Students wish to revise After Completion of entire Portion, they can go Through All the Subject Guess Paper to have grip in every corner of the Subject, BSE Odisha Question Paper Provide Matric Latest and Last Year Exam Study Material for Syllabus, Question Paper etc, Hindi, English Medium Pdf Format.

Avatar_small
SBI atm pin generati 说:
2023年1月25日 16:31

State Bank of India is the most popular and trusted Bank of India, which has over crores of active customers. State Bank of India brings various features in their banking system, which allows their customers to have access at their fingertips. SBI atm pin generation Earlier the debit card PIN generation was always a hassle, as the customer had to wait for the PIN through courier. In present days, there are multiple ways by which one can get their Debit card PIN generated.

Avatar_small
Safeway Pharmacy Nea 说:
2023年1月30日 22:13

This is widely spread in the USA and they do have stores for grocery, fuel, and Pharmacy. The locate me icon on the official website does help you find any of the stores or fuel centers in a quick way. Safeway Pharmacy Near Me The shopping becomes easy, as they bring all vaults of products with multiple brands. The associates in Safe Way stores well prepared to support the customer’s during their shopping.

Avatar_small
+2 Question Paper 20 说:
2023年2月10日 16:42

+2 Question Paper 2024 and Board Model Paper 2024 The Board of Secondary Education has declared the Board Model Paper 2024 of 2nd Year Intermediate Class. +2 Question Paper 2024 If you are also one of the enrolling students of this board and waiting for 2nd Year Intermediate Model Paper 2024. Important Question Paper 2024 then take the patient for some time and check the final passing list through the link which is mentioned at the bottom of the page.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter