Skip to content

Commit d85b7dc

Browse files
committed
update for book v3.0.0
1 parent b9a340e commit d85b7dc

File tree

12 files changed

+45
-57
lines changed

12 files changed

+45
-57
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
/db/*.sqlite3-journal
1313

1414
# Ignore all logfiles and tempfiles.
15-
/log/*.log
15+
/log/*
16+
!/log/.keep
1617
/tmp

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.3
1+
2.3.0

Gemfile

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source 'https://rubygems.org'
2-
ruby '2.2.3'
2+
ruby ‘2.3.0
33
gem 'rails', '4.2.5'
44
gem 'sass-rails', '~> 5.0'
55
gem 'uglifier', '>= 1.3.0'
@@ -9,8 +9,6 @@ gem 'turbolinks'
99
gem 'jbuilder', '~> 2.0'
1010
group :development, :test do
1111
gem 'byebug'
12-
end
13-
group :development do
1412
gem 'web-console', '~> 2.0'
1513
gem 'spring'
1614
end
@@ -22,8 +20,6 @@ group :development do
2220
gem 'better_errors'
2321
gem 'quiet_assets'
2422
gem 'rails_layout'
25-
end
26-
group :development, :test do
2723
gem 'sqlite3'
2824
end
2925
group :production do

README.textile

+12-15
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ h4. Latest Book Version: 2.2.2
1818

1919
The most recent version of the book was written for Rails 4.2 and released October 30, 2015. 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.
2020

21-
h4. Application Version: 2.2.2
21+
h4. Application Version: 3.0.0
2222

23-
This example application (here on GitHub) matches the code in the book.
23+
This example application (here on GitHub) is ahead of the code in the book.
2424

2525
For recent changes, see:
2626

@@ -73,19 +73,19 @@ This is one in a series of Rails example apps and tutorials from the "RailsApps
7373

7474
h2. Accounts You Will Need
7575

76-
To send email from the application, you will need a "Gmail":https://accounts.google.com/SignUp?service=mail account. You can get a free "Gmail":https://accounts.google.com/SignUp?service=mail account if you don't already have one. Other services, such as "Mandrill":http://mandrill.com/, can be used to send email from the application. Or you can connect directly to an SMTP mail server to send email. See the article "Send Email with Rails":http://railsapps.github.io/rails-send-email.html for more information.
77-
7876
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.
7977

8078
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.
8179

80+
To send email from the application, you will need a "Mandrill":http://mandrill.com/ account. Sign up for a MailChimp account to get started. After you've created your MailChimp account, see the instructions [How do I use Mandrill if I already have a MailChimp account?](http://help.mandrill.com/entries/21681117-how-do-i-use-mandrill-if-i-already-have-a-mailchimp-account). Or you can connect directly to an SMTP mail server to send email. See the article "Send Email with Rails":http://railsapps.github.io/rails-send-email.html for more information.
81+
8282
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.
8383

8484
h2. Dependencies
8585

8686
Before generating your application, you will need:
8787

88-
* The Ruby language - version 2.2
88+
* The Ruby language - version 2.3
8989
* The Rails gem - version 4.2
9090

9191
See the article "Installing Rails":http://railsapps.github.io/installing-rails.html for instructions about setting up Rails and your development environment.
@@ -181,7 +181,6 @@ h3. Gems
181181

182182
Here are the gems used by the application:
183183

184-
* "activerecord-tableless":https://github.com/softace/activerecord-tableless - helps to use Rails without a database
185184
* "foundation-rails":https://github.com/zurb/foundation - front-end framework
186185
* "gibbon":https://github.com/amro/gibbon - access to the MailChimp API
187186
* "high_voltage":https://github.com/thoughtbot/high_voltage - for static pages like "about"
@@ -222,8 +221,8 @@ Add your credentials to the file *config/secrets.yml*:
222221
# if you're sharing your code publicly.
223222

224223
development:
225-
email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
226-
email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
224+
mandrill_username: <%= ENV["MANDRILL_USERNAME"] %>
225+
mandrill_api_key: <%= ENV["MANDRILL_API_KEY"] %>
227226
mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
228227
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
229228
domain_name: example.com
@@ -236,18 +235,16 @@ test:
236235
# Do not keep production secrets in the repository,
237236
# instead read values from the environment.
238237
production:
239-
email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
240-
email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
238+
mandrill_username: <%= ENV["MANDRILL_USERNAME"] %>
239+
mandrill_api_key: <%= ENV["MANDRILL_API_KEY"] %>
241240
mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
242241
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
243242
domain_name: <%= ENV["DOMAIN_NAME"] %>
244243
owner_email: <%= ENV["OWNER_EMAIL"] %>
245244
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
246245
</pre>
247246

248-
All configuration values in the *config/secrets.yml* file are available anywhere in the application as variables. For example, @Rails.application.secrets.email_provider_username@ will return the string set in the Unix environment variable @GMAIL_USERNAME@.
249-
250-
For the Gmail username and password, enter the credentials you use to log in to Gmail when you check your inbox. See the article "Send Email with Rails":http://railsapps.github.io/rails-send-email.html if you are using Google two factor authentication.
247+
All configuration values in the *config/secrets.yml* file are available anywhere in the application as variables. For example, @Rails.application.secrets.mandrill_username@ will return the string set in the Unix environment variable @MANDRILL_USERNAME@.
251248

252249
To add an environment variable for the MailChimp API key, "Log in to MailChimp":https://admin.mailchimp.com/ to get your API key. Click your name at the top of the navigation menu, then click "Account Settings." Click "Extras," then "API keys."
253250

@@ -292,8 +289,8 @@ You can deploy from the command line.
292289
If you've set configuration values in the *config/secrets.yml* file, you'll need to set them as Heroku environment variables. You can set Heroku environment variables directly with @heroku config:add@. For example:
293290

294291
<pre>
295-
$ heroku config:add GMAIL_USERNAME='[email protected]' GMAIL_PASSWORD='secret'
296-
$ heroku config:add MAILCHIMP_API_KEY='mykey' MAILCHIMP_LIST_ID='mylistid'
292+
$ heroku config:add MANDRILL_USERNAME='MyUsername' MANDRILL_API_KEY='my-key'
293+
$ heroku config:add MAILCHIMP_API_KEY='my-key' MAILCHIMP_LIST_ID='mylistid'
297294
$ heroku config:add OWNER_EMAIL='[email protected]' DOMAIN_NAME='myapp.herokuapp.com'
298295
</pre>
299296

app/controllers/contacts_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def new
77
def create
88
@contact = Contact.new(secure_params)
99
if @contact.valid?
10-
UserMailer.contact_email(@contact).deliver
10+
UserMailer.contact_email(@contact).deliver_now
1111
flash[:notice] = "Message sent from #{@contact.name}."
1212
redirect_to root_path
1313
else

app/mailers/user_mailer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class UserMailer < ActionMailer::Base
1+
class UserMailer < ApplicationMailer
22
default from: "[email protected]"
33

44
def contact_email(contact)

app/models/contact.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class Contact
77
validates_presence_of :name
88
validates_presence_of :email
99
validates_presence_of :content
10-
validates_format_of :email, with: /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i
10+
validates_format_of :email,
11+
with: /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i
1112
validates_length_of :content, :maximum => 500
1213

1314
end

app/views/user_mailer/contact_email.text.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ You received a message from <%= @contact.name %> with email address <%= @contact
22

33
The visitor said:
44

5-
"<%= @contact.content %>"
5+
"<%= @contact.content %>"

app/views/visitors/new.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</section>
66
<section>
77
<div class="column">
8-
<h2>Stay in touch.</h2>
8+
<h3>Stay in touch.</h3>
99
</div>
1010
<div class="column">
1111
<div class="form-centered">

config/environments/development.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@
2828
config.assets.debug = true
2929

3030
config.action_mailer.smtp_settings = {
31-
address: "smtp.gmail.com",
31+
address: "smtp.mandrillapp.com",
3232
port: 587,
33-
domain: Rails.application.secrets.domain_name,
34-
authentication: "plain",
35-
enable_starttls_auto: true,
36-
user_name: Rails.application.secrets.email_provider_username,
37-
password: Rails.application.secrets.email_provider_password
33+
user_name: Rails.application.secrets.mandrill_username,
34+
password: Rails.application.secrets.mandrill_api_key
3835
}
3936
# ActionMailer Config
4037
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
@@ -43,7 +40,6 @@
4340
# Send email in development mode?
4441
config.action_mailer.perform_deliveries = true
4542

46-
4743
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
4844
# yet still be able to expire them through the digest params.
4945
config.assets.digest = true

config/environments/production.rb

+13-16
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,22 @@
7171
# Send deprecation notices to registered listeners.
7272
config.active_support.deprecation = :notify
7373

74-
config.action_mailer.smtp_settings = {
75-
address: "smtp.gmail.com",
76-
port: 587,
77-
domain: Rails.application.secrets.domain_name,
78-
authentication: "plain",
79-
enable_starttls_auto: true,
80-
user_name: Rails.application.secrets.email_provider_username,
81-
password: Rails.application.secrets.email_provider_password
82-
}
83-
# ActionMailer Config
84-
config.action_mailer.default_url_options = { :host => Rails.application.secrets.domain_name }
85-
config.action_mailer.delivery_method = :smtp
86-
config.action_mailer.perform_deliveries = true
87-
config.action_mailer.raise_delivery_errors = false
88-
89-
9074
# Use default logging formatter so that PID and timestamp are not suppressed.
9175
config.log_formatter = ::Logger::Formatter.new
9276

9377
# Do not dump schema after migrations.
9478
config.active_record.dump_schema_after_migration = false
79+
80+
# email enabled in production
81+
config.action_mailer.default_url_options = { :host => Rails.application.secrets.domain_name }
82+
config.action_mailer.delivery_method = :smtp
83+
config.action_mailer.perform_deliveries = true
84+
config.action_mailer.raise_delivery_errors = false
85+
config.action_mailer.smtp_settings = {
86+
address: "smtp.mandrillapp.com",
87+
port: 587,
88+
user_name: Rails.application.secrets.mandrill_username,
89+
password: Rails.application.secrets.mandrill_api_key
90+
}
91+
9592
end

config/secrets.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# if you're sharing your code publicly.
1212

1313
development:
14-
email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
15-
email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
16-
domain_name: example.com
14+
mandrill_username: <%= ENV["MANDRILL_USERNAME"] %>
15+
mandrill_api_key: <%= ENV["MANDRILL_API_KEY"] %>
1716
mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
1817
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
18+
domain_name: example.com
1919
owner_email: <%= ENV["OWNER_EMAIL"] %>
2020
secret_key_base: very_long_random_string
2121

@@ -25,10 +25,10 @@ test:
2525
# Do not keep production secrets in the repository,
2626
# instead read values from the environment.
2727
production:
28-
email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
29-
email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
28+
mandrill_username: <%= ENV["MANDRILL_USERNAME"] %>
29+
mandrill_api_key: <%= ENV["MANDRILL_API_KEY"] %>
30+
mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
31+
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
3032
domain_name: <%= ENV["DOMAIN_NAME"] %>
31-
mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
32-
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
3333
owner_email: <%= ENV["OWNER_EMAIL"] %>
3434
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

0 commit comments

Comments
 (0)