百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rails-devise

> 编程语言
开源

带有 Devise 进行身份验证的 Rails 5.0 入门应用程序。

511 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

带有 Devise 进行身份验证的 Rails 5.0 入门应用程序。

h1. !http://railsapps.github.io/images/rails-36x36.jpg(Rails Devise)! Rails and Devise

Rails 5.0 example application that provides authentication and user management.

  • "Devise":https://github.com/plataformatec/devise for user management and authentication
  • "Bootstrap":http://getbootstrap.com/ or "Foundation":http://foundation.zurb.com/ front-end frameworks

Use this example application as a starter app for your own web applications. A complete "Devise Tutorial":http://railsapps.github.io/rails-devise/ is available.

You can build this application in only a few minutes using the "Rails Composer":http://railsapps.github.io/rails-composer/ tool, choosing either a Bootstrap or Foundation front-end framework, as well as many other options, such as Haml or Slim. You get login and signup pages (also "edit account" and “forgot password” pages) that are more attractive than the default Devise pages.

h4. !http://railsapps.github.io/images/join/join-railsapps.png(Join RailsApps)!:http://railsapps.github.io/

h4. From the RailsApps Project

The "RailsApps":http://railsapps.github.io/ open source project offers starter applications and tutorials for Rails developers. Generate the applications with the Rails Composer tool.

All the code is explained in the Capstone Rails Tutorials. You can purchase the "Capstone Rails Tutorials":https://tutorials.railsapps.org/ to support the project.

h4. If You Are New to Rails

If you're new to Rails, see "What is Ruby on Rails?":http://railsapps.github.io/what-is-ruby-rails.html, the book "Learn Ruby on Rails":http://learn-rails.com/learn-ruby-on-rails.html, and recommendations for a "Rails tutorial":https://tutorials.railsapps.org/rails-tutorial.

h4. Devise Tutorial

An in-depth "Devise Tutorial":http://railsapps.github.io/rails-devise/ is available from the RailsApps project. The tutorial describes the example application in detail, so there is no mystery code.

h2. What Is Implemented -- and What Is Not

The example application can be used as the basis for a website that provides a login page and user management. With knowledge of Rails, the website can be adapted and customized to your needs. Features include:

  • Home page
  • Navigation bar
  • Sign up (create account)
  • Login
  • "Forgot password?" feature
  • "Remember me" (stay logged in) feature
  • Edit account (edit user profile)
  • List of users

The list of users is visible to anyone. Use authentication to restrict it to the user who was created first, or implement authorization to restrict it to an administrator. See the "rails-devise-pundit":https://github.com/RailsApps/rails-devise-pundit example application if you wish to add authorization.

h4. Database

The application requires a database. The example application uses SQLite with Rails ActiveRecord. You can easily substitute PostgreSQL, MySQL, or other databases.

h4. Front-end Framework

The example application (here in the GitHub repository) integrates Bootstrap for a navigation bar and flash messages. The "rails_layout":https://github.com/RailsApps/rails_layout gem is included so you can switch to the Foundation front-end framework.

h2. Similar Examples and Tutorials

This is one in a series of Rails example apps and tutorials from the "RailsApps Project":http://railsapps.github.io/. See a list of additional "Rails examples, tutorials, and starter apps":http://railsapps.github.io/rails-examples-tutorials.html. Related example applications may be useful:

  • "Learn Rails":https://github.com/RailsApps/learn-rails companion to the book "Learn Ruby on Rails":http://learn-rails.com/learn-ruby-on-rails.html
  • "Foundation and Rails":http://railsapps.github.io/rails-foundation/ shows how to integrate Foundation
  • "Bootstrap and Rails":http://railsapps.github.io/rails-bootstrap/ shows to integrate Bootstrap
  • "OmniAuth and Rails":https://github.com/RailsApps/rails-omniauth uses OmniAuth for authentication
  • "Devise and Pundit and Rails":https://github.com/RailsApps/rails-devise-pundit uses Pundit for authorization

h2. Accounts You Will Need

Devise provides a "Forgot Password?" feature that resets a password and sends instructions to the user. You'll need an email service provider to send email from the application. You can use "Gmail":https://accounts.google.com/SignUp?service=mail during development. You can get a free "Gmail":https://accounts.google.com/SignUp?service=mail account if you don't already have one. For production, Gmail is not robust. Use transactional email services, such as "SendGrid":https://sendgrid.com/, to send email in production. See the article "Send Email with Rails":http://railsapps.github.io/rails-send-email.html for more information.

We provide instructions to deploy the application to "Heroku":https://www.heroku.com/ which provides Rails application hosting. It costs nothing to set up a Heroku account and deploy as many applications as you want. To deploy an app to Heroku, you must have a Heroku account. Visit Heroku "to set up an account":https://id.heroku.com/signup/devcenter.

h2. Dependencies

Before generating your application, you will need:

  • The Ruby language - version 2.3.1
  • The Rails gem - version 5.0

See the article "Installing Rails":http://railsapps.github.io/installing-rails.html for instructions about setting up Rails and your development environment.

h2. Getting the Application

h3. Local

You have several options for getting the code on your own machine. You can fork, clone, or generate.

h4. Fork

If you'd like to add features (or bug fixes) to improve the example application, you can fork the GitHub repo and "make pull requests":http://help.github.com/send-pull-requests/. Your code contributions are welcome!

h4. Clone

If you want to copy and customize the app with changes that are only useful for your own project, you can clone the GitHub repo. You'll need to search-and-replace the project name throughout the application. You probably should generate the app instead (see below). To clone:

$ git clone git://github.com/RailsApps/rails-devise.git

You'll need "git":http://git-scm.com/ on your machine. See "Rails and Git":http://railsapps.github.io/rails-git.html.

h4. Generate

If you want to use the project as a starter application, use the "Rails Composer":http://railsapps.github.io/rails-composer/ tool to generate a new version of the example app. You'll be able to give it your own project name when you generate the app. Generating the application gives you additional options.

To build the example application, Rails 5.0 must be installed in your development environment. Run the command:

$ rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

The @$@ character indicates a shell prompt; don't include it when you run the command.

This creates a new Rails app named @rails-devise@ on your computer. You can use a different name if you wish.

You'll see a prompt:

option Build a starter application? 1) Build a RailsApps example application 2) Contributed applications 3) Custom application

Enter "1" to select Build a RailsApps example application. You'll see a prompt:

option Choose a starter application. 1) learn-rails 2) rails-bootstrap 3) rails-foundation 4) rails-mailinglist-activejob 5) rails-omniauth 6) rails-devise 7) rails-devise-roles 8) rails-devise-pundit 9) rails-signup-download 10) rails-stripe-checkout

Choose rails-devise. The Rails Composer tool may give you other options (other applications may have been added since these notes were written).

The application generator template will ask you for additional preferences:

question Web server for development? 1) WEBrick (default) 2) Thin 3) Unicorn 4) Puma 5) Phusion Passenger (Apache/Nginx) 6) Phusion Passenger (Standalone) question Web server for production? 1) Same as development 2) Thin 3) Unicorn 4) Puma 5) Phusion Passenger (Apache/Nginx) 6) Phusion Passenger (Standalone) question Database used in development? 1) SQLite 2) PostgreSQL 3) MySQL question Template engine? 1) ERB 2) Haml 3) Slim question Test framework? 1) None 2) RSpec with Capybara question Front-end framework? 1) None 2) Bootstrap 3.3 3) Bootstrap 2.3 4) Zurb Foundation 5.5 5) Zurb Foundation 4.0 6) Simple CSS setup The Devise 'forgot password' feature requires email. question Add support for sending email? 1) None 2) Gmail 3) SMTP 4) SendGrid 5) Mandrill question Devise modules? 1) Devise with default modules 2) Devise with Confirmable module question Use a form builder gem? 1) None 2) SimpleForm extras Set a robots.txt file to ban spiders? (y/n) extras Create a GitHub repository? (y/n) extras Use or create a project-specific rvm gemset? (y/n)

h4. Web Servers

If you plan to deploy to Heroku, select Unicorn as your production webserver. Unicorn is recommended by Heroku.

h4. Database

Use SQLite for development on Mac or Linux, unless you already have PostgreSQL installed locally. Use PostgreSQL if you plan to deploy to Heroku. You can easily change the database later if you select SQLite to start.

h4. Template Engine

The example application uses the default "ERB" Rails template engine. Optionally, you can use another template engine, such as Haml or Slim. See instructions for "Haml and Rails":http://railsapps.github.io/rails-haml.html.

h4. Testing

If you are a beginner, select "None."

h4. Front-end Framework

The example in the GitHub repository was built without a front-end framework. Use Zurb Foundation 5.5 or Bootstrap 3.3 if you like. Choosing either Foundation or Bootstrap will automatically install Devise views with attractive styling.

h4. Email

Choose Gmail for development if you already have a Gmail account. Choose SendGrid or Mandrill for production if your site will be heavily used.

h4. Devise Modules

The example in the GitHub repository uses Devise with default modules.

h4. Other Choices

Set a robots.txt file to ban spiders if you want to keep your new site out of Google search results.

If you choose to create a GitHub repository, the generator will prompt you for a GitHub username and password.

It is a good idea to use "rvm":https://rvm.io/, the Ruby Version Manager, and create a project-specific rvm gemset (not available on Windows). See "Installing Rails":http://railsapps.github.io/installing-rails.html.

h4. Troubleshooting

If you get an error "OpenSSL certificate verify failed" or "Gem::RemoteFetcher::FetchError: SSL_connect" see the article "OpenSSL errors and Rails":http://railsapps.github.io/openssl-certificate-verify-failed.html.

h3. Edit the README

If you're storing the app in a GitHub repository, please edit the README files to add a description of the app and your contact info. If you don't change the README, people will think I am the author of your version of the application.

h2. Getting Started

See the article "Installing Rails":http://railsapps.github.io/installing-rails.html to make sure your development environment is prepared properly.

h3. Use RVM

I recommend using "rvm":https://rvm.io/, the Ruby Version Manager, to create a project-specific gemset for the application. If you generate the application with the Rails Composer tool, you can create a project-specific gemset.

h3. Gems

Here are the gems used by the application:

  • "devise":http://github.com/plataformatec/devise - authentication and user management

These gems make development easier:

  • "better_errors":https://github.com/charliesome/better_errors - helps when things go wrong
  • "rails_layout":https://github.com/RailsApps/rails_layout - generates files for an application la

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言