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

rails_new

> 后端框架
开源

一个经过精心设计的模板,用于构建现代的 Rails 应用。只需几分钟即可开始,而非数小时。

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

工具介绍

一个经过精心设计的模板,用于构建现代的 Rails 应用。只需几分钟即可开始,而非数小时。

rails_new

A thoughtfully designed template for building modern Rails apps

Get started on your new app within minutes instead of hours

  • rails_new
    • Getting started
    • Optional configuration options
    • Environment variables
    • Contents
      • Base system
      • General
      • Frontend
      • Development
      • Test
      • Production
    • Removed
    • Notes
      • Account vs User
      • Heroku Buildpacks
      • React
      • TypeScript
      • Hot Module Replacement (HMR)
      • JavaScript/TypeScript Tests
      • Polyfills
      • Custom classes
      • Gemfile.dev / Gemfile.dev.lock
      • Rack::RejectTrace middleware
      • Favicons
    • Docker
      • Usage examples:
    • TODO
    • License

Getting started

To get going clone this repository and perform the following steps:

  1. Run rails credentials:edit to re-generate config/master.key and create config/credentials.yml.enc.
  2. If your application requires ActiveStorage, run rails active_storage:install to generate a migration that creates the necessary tables. Use rails db:migrate to run the migration.
  3. You can now run bin/configure, which will help you in configuring the template.

As an alternative to running the script you can perform all of the following steps manually.

  1. Change application name in config/application.rb.
  2. Update database.yml to reflect the new application name.
  3. Update TODO items in config/environments/production.rb.
  4. If you plan on using Figaro, copy config/application.yml.example to config/application.yml.
  5. ESLint is preconfigured for modern JS with React support (using Prettier). If you want to use it install packages with npm install / yarn [install], otherwise remove .eslintrc and package.json.
  6. If you don't plan on tracking the template, you can remove the remote, otherwise rename it and add your new remote as appropriate.:
    bash
    $ git remote rename origin rails_new
    $ git remote add origin ...

Optional configuration options

  • If you want to use Sentry, you'll need to:
    1. Create two projects under your organization on Sentry. This way you can keep frontend and backend errors separate.
    2. Set SENTRY_DSN_BACKEND and SENTRY_DSN_FRONTEND environment variables. Both are optional - errors will only be reported if the respective variable is set.
  • New Relic is pre configured in config/newrelic.yml, but you need to comment in the environment variables for it work on Heroku (lines 10 and 17).
  • The app is preconfigured for Google Analytics, just add GOOGLE_ANALYTICS_ID to the environment.
  • We prefer to use vanilla Sidekiq for worker/queue management. If you prefer to use ActiveJob please see the configuration/options that were removed in 59cf38d.

Environment variables

Variable Comment
SENTRY_DSN_BACKEND Used to report backend errors to Sentry.
SENTRY_DSN_FRONTEND Used to report frontend errors to Sentry.
BLOCK_HTTP_TRACE Disables HTTP TRACE method if set to true/t/1
BUNDLE_GEMFILE Useful when using a Gemfile.dev
DATABASE_URL Used for production env, automatically set by Heroku
GOOGLE_ANALYTICS_ID Will be added to the main application layout if set
HOST Your base URI, e.g. https://myapp.herokuapp.com
NEW_RELIC_APP_NAME Used in config/newrelic.yml
NEW_RELIC_LICENSE_KEY Used in config/newrelic.yml
PORT Port Puma will listen on, defaults to 3000
RACK_TIMEOUT_SERVICE_TIMEOUT Limit for Rack::Timeout, defaults to 15 seconds
RAILS_LOG_TO_STDOUT Set by Heroku Ruby buildpack, set manually on other platforms if needed
RAILS_MAX_THREADS Number of Puma threads, defaults to 5
REDIS_URL Used in config/cable.yml
WEB_CONCURRENCY Number of Puma workers. We default to threads only, no workers

Contents

All of the following have been installed and pre-configured:

Base system

  • Ruby
  • Ruby on Rails
  • PostgreSQL >= 9.2
  • pg for ActiveRecord
  • NodeJS

NOTE: We recommend that you install and manage these system dependencies using a combination of Homebrew (Postgres), asdf-vm (Ruby, NodeJS) and Bundler (Ruby on Rails). If you are starting fresh on a new system you may want to manage these package managers with a script like the thoughtbot laptop script with the option to add your own opinionated extensions, e.g. this. Your code base should be under version control, why not your system toolkit and configuration as well?

General

  • devise
  • figaro
  • foreman
  • fast_jsonapi
  • pundit
  • sidekiq

Frontend

All of these are managed by yarn.

  • bootstrap4
  • jquery
  • jquery-ujs
  • popper.js

Development

  • Brakeman
  • bullet
  • letter_opener
  • memory_profiler
  • newrelic_rpm
  • nullalign
  • pry
  • pry-byebug
  • pry-doc
  • rack-mini-profiler
  • RuboCop

Test

Rspec has been preconfigured for Rails 5.1+ system tests.

  • No need to require 'rails_helper, we do it in .rspec
  • bundler-audit (runs on CircleCI)
  • capybara
  • factory_bot_rails
  • shoulda-matchers
  • webmock

Production

  • sentry-ruby
  • heroku-deflater
  • lograge
  • rails_12factor
  • rack-timeout: Configured via env variables, see documentation
  • secureheaders

Removed

The following default Rails gems have been removed:

  • coffee-rails
  • jbuilder

Notes

Account vs User

Authentication concerns (your typical Devise configuration) are handled by the Account model. To connect this to one of several potential user roles the polymorphic authenticatable relationship is used.

Heroku Buildpacks

Note that for everything to work properly on Heroku you need to set up your buildpacks like this:

heroku buildpacks:clear
heroku buildpacks:add heroku/metrics
heroku buildpacks:set heroku/nodejs
heroku buildpacks:add heroku/ruby

React

React support has been preconfigured together with react-rails.

When creating a new component you want to mount in the view, place it under the views folder. react-rails will perform module lookup relative to that folder and automatically require it under the hood so it gets included in the application pack. For example, calling the following helper in your view file:

ruby
react_component("dashboard/properties_list")

will require views/dashboard/properties_list and mount it in place of the helper element. See the docs for details about working with react-rails.

TypeScript

TypeScript is supported out of the box.

It is important to note that TypeScript code is loaded by babel-loader. Because of that, you need to perform type checking in a separate process. This could either be your editor, or running yarn types-watch in your terminal to compile your code in watch mode.

This will not interfere with HMR (see below) as TypeScript compiler is instructed only to type-check your code, not to emit compiled modules.

For extra safety, there is a CI build step that runs tsc to make sure TypeScript code compiles

Hot Module Replacement (HMR)

HMR is also supported out of the box. All you need to do is hot-export your module, like so:

javascript
import React from "react";
import { hot } from "react-hot-loader/root";

class Welcome extends React.Component {
  render() {
    return 
Hello, {this.props.name}
;
  }
}

export default hot(Welcome);

This will allow you to continue working on your JS code without losing application state in the browser.

JavaScript/TypeScript Tests

The repo comes pre-configured with jest. You can write your tests in JavaScript or TypeScript.

We're following the convention of placing tests next to the file they're testing. They will be run as long as they have test, (e.g. MyComponent.test.ts) in the name.

You are encouraged to place your testing utility files under app/javascript/test.

To run your tests, run:

bash
yarn test

Polyfills

Polyfills are included automatically thanks to @babel/preset-env. See babel.config.js for configuration options.

Custom classes

  • ApplicationDecorator: lightweight alternative to Draper or similar gems.
  • ApplicationForm: Minimal form class based on ActiveModel.
  • ApplicationPresenter: a subclass of ApplicationDecorator for presenters, includes tag helpers.

All custom classes are fully documented with yard and come with generators.

Use yard doc to generate documentation and yard server --reload or yard server --gems to start a local documentation server.

Gemfile.dev / Gemfile.dev.lock

If you want to add specific gems for development that may not be interesting for other developers, you can add a Gemfile.dev (ignored by our .gitignore). Gems listed there can be installed with bundle install --gemfile Gemfile.dev and the resulting lock file is gitignored too.

Example Gemfile.dev:

ruby
source 'https://rubygems.org'

eval_gemf

Issues· 10 开放

查看全部 Issues在 GitHub 打开

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

> 标签

Rubyfigaroherokupryrails

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

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架