Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rails-devise-pundit

> 编程语言
Open source

Rails 5.0 starter app with Devise for authentication and Pundit for authorization.

480 stars0 likes1 views
WebsiteGitHub

About

Rails 5.0 starter app with Devise for authentication and Pundit for authorization.

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

Rails 5.0 example application that provides user management, authentication, and authorization. The application shows how to integrate:

  • "Devise":https://github.com/plataformatec/devise for user management and authentication
  • "Pundit":https://github.com/elabs/pundit for authorization
  • "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. For a complete explanation of the code, see the tutorials:

  • "Rails and Pundit Tutorial":http://railsapps.github.io/rails-devise-pundit/
  • "Role-Based Authorization Tutorial":http://railsapps.github.io/rails-devise-roles/
  • "Rails and Devise Tutorial":http://railsapps.github.io/rails-devise/
  • "RSpec Tutorial":http://railsapps.github.io/rspec.html

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.

There's also a helpful article on "Rails Authorization":http://railsapps.github.io/rails-authorization.html comparing CanCan and Pundit gems, and looking at simple role-based authorization.

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.

h2. What Is Implemented -- and What Is Not

This application extends the "rails-devise":https://github.com/RailsApps/rails-devise example application to add authorization with Pundit. The "rails-devise":https://github.com/RailsApps/rails-devise example application provides:

  • 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

This "rails-devise-pundit":https://github.com/RailsApps/rails-devise-pundit example application adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role. With this application:

  • an admin can see a list of users
  • an admin can change a user's role
  • an ordinary user can't see a list of users
  • an ordinary user can't change their role
  • an ordinary user can't see (or edit) another user's profile
  • an ordinary user can see (and edit) their own user profile

After examining the example application, you'll be able to implement access control in your own applications.

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 Rails":https://github.com/RailsApps/rails-devise uses Devise for authentication

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 "Mandrill":http://mandrill.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-pundit.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-pundit -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-pundit@ 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-pundit. 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) Twitter Bootstrap 3.3 3) Twitter 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 with the Bootstrap 3 front-end framework. Use Zurb Foundation 5.5 if you like. Choosing either Bootstrap or Foundation will automatically install 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 M

Issues· 13 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

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