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

learn-rails

> 后端框架
开源

一个用于配合《学习 Ruby on Rails》一书的 Rails 5.1 应用程序示例。

397 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

一个用于配合《学习 Ruby on Rails》一书的 Rails 5.1 应用程序示例。

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

A Rails 5.1 example application to accompany the book "Learn Ruby on Rails":http://learn-rails.com/learn-ruby-on-rails.html.

The book introduces basic concepts of Rails development by showing the reader how to build an application that can be used for a typical small business website.

You can build this application in only a few minutes using the "Rails Composer":http://railsapps.github.io/rails-composer/ tool.

h2. The Book Set: 'Learn Ruby on Rails'

h3. !http://railsapps.github.io/images/learn-rails-cover-130x161.jpg(Learn Ruby on Rails)!:http://learn-rails.com/learn-ruby-on-rails.html

This example application is fully documented in the book set "Learn Ruby on Rails":http://learn-rails.com/learn-ruby-on-rails.html. May I suggest, you should "get the books":http://learn-rails.com/learn-ruby-on-rails.html.

With the books, a complete beginner can create this application without any additional knowledge. The books explain all the code, introducing basic concepts of Rails application development and professional practices.

h4. Book Two, Latest Version: 4.1.0

There are two books. Book One does not contain code from the application and does not change often.

Book Two contains a tutorial application and changes frequently. The most recent version of the book was written for Rails 5.1 and released July 3, 2017. Please make sure you have the newest version of the book (or the code examples may not work). The book version is shown on the title page. "Get the book":http://learn-rails.com/learn-ruby-on-rails.html if you need the new version.

h4. Application Version: 4.1.0

This example application (here on GitHub) matches the code in Book Two.

For recent changes, see:

  • "CHANGELOG":https://github.com/RailsApps/learn-rails/blob/master/CHANGELOG.textile for a summary
  • "commit log":https://github.com/RailsApps/learn-rails/commits/master for code changes

h2. A Practical Application

The example application is more than a learning exercise. The tutorial shows how to build a basic website, using practices recommended by experienced Rails developers. You'll build a real-world Rails application that can be used by a typical small business. With knowledge of Rails, the website can be adapted and customized to your needs. Features include:

  • Home page
  • Navigation bar
  • "About" page
  • Contact page with "contact request" form
  • Mailing list sign-up form

h4. Additional Pages

The application uses the "high_voltage gem":https://github.com/thoughtbot/high_voltage for the "About" page. Additional pages can easily be added. The high_voltage gem makes it easy to add pages with static content (text that doesn't change) incorporating elements of a site-wide application layout such as header, navigation links, and footer.

For example, using the high_voltage gem, you could add pages for:

  • FAQ
  • News
  • Legal disclaimers

h4. Mailing List Opt-In

The application home page contains a form that encourages a visitor to enter an email address to sign up for a mailing list. It can be used to collect email addresses for a newsletter or announcement mailings. The tutorial shows how to set up a MailChimp account and use the MailChimp API to add email addresses to a MailChimp list.

h4. Contact Form

The Contact page includes a "contact request" form. The contact form can be adapted for other purposes, such as an appointment request, or customized as a survey form.

When the visitor submits the form, an email message goes to the site owner containing the contents of the form.

h4. No Database

The application does not require a database. No pages are generated using information from a database and no user-submitted data is saved to a database. However, the sqlite3 gem must be present in the Gemfile because Rails ActiveRecord is used for form validation.

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:

  • "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
  • "Devise and Pundit and Rails":https://github.com/RailsApps/rails-devise-pundit uses Pundit for authorization

h2. Accounts You Will Need

The application includes a form that allows website visitors to "opt-in" to a mailing list. You'll need a "MailChimp":http://mailchimp.com/ account, which is free. MailChimp allows you to send up to 12,000 emails/month to a list of 2000 or fewer subscribers for free. There is no cost to set up an account. After you have set up a MailChimp account, create a new mailing list where you can collect email addresses of visitors who have asked to subscribe to a newsletter. The MailChimp "Lists" page has a button for "Create List." The list name and other details are up to you.

With MailChimp, you can send a welcome message automatically when the visitor signs up for the mailing list. It’s a bit difficult to find the MailChimp option to create a welcome message. Strangely, MailChimp considers a welcome message a "form." Here's how to find it. On the MailChimp "Lists" page, click the "down arrow" for a menu and click "Signup forms." Then click "Link to a form." On the "Create Forms" page, there is a dropdown list of "Forms & Response Emails." The gray box shows "Signup form." Click the down arrow. Select the menu item named "Final 'Welcome' Email" and you'll be able to create a welcome message.

To send email from the application, you will need a "SendGrid":https://sendgrid.com/ account.

We provide instructions to deploy the tutorial 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.4.1
  • The Rails gem - version 5.1

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":https://help.github.com/articles/about-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/learn-rails.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.1 must be installed in your development environment. Run the command:

$ rails new learn-rails -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.

The @-m@ option loads an application template that is hosted on GitHub.

This creates a new Rails app named @learn-rails@ 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 learn-rails. The Rails Composer tool may give you other options (other applications may have been added since these notes were written).

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:

  • "foundation-rails":https://github.com/zurb/foundation - front-end framework
  • "gibbon":https://github.com/amro/gibbon - access to the MailChimp API
  • "high_voltage":https://github.com/thoughtbot/high_voltage - for static pages like "about"
  • "simple_form":http://simple-form.plataformatec.com.br/ - forms made easy

These gems make development easier:

  • "better_errors":https://github.com/charliesome/better_errors - helps when things go wrong
  • "quiet_assets":https://github.com/evrone/quiet_assets - suppresses distracting messages in the log
  • "rails_layout":https://github.com/RailsApps/rails_layout - generates files for an application layout

h3. Install the Required Gems

If you used the "Rails Composer":http://railsapps.github.io/rails-composer/ tool to generate the example app, the application template script has already run the @bundle install@ command.

If not, you should run the @bundle install@ command to install the required gems on your computer:

$ bundle install

You can check which gems are installed on your computer with:

$ gem list

Keep in mind that you have installed these gems locally. When you deploy the app to another server, the same gems (and versions) must be available.

h3. Configuration File

To consolidate configuration settings in a single location, we store credentials in the config/secrets.yml file. To keep your credentials private, use Unix environment variables to set your credentials. See the article "Rails Environment Variables":http://railsapps.github.io/rails-environment-variables.html for more information.

Add your credentials to the file config/secrets.yml:

Make sure the secrets in this file are kept private

if you're sharing your code publicly.

development: email_provider_username:

Issues· 15 开放

查看全部 Issues在 GitHub 打开

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

> 标签

Rubybooksrailsrubyruby-on-rails

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

> 工具信息

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

> 相关工具

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