learnenough / sample_app_6th_ed Goto Github PK
View Code? Open in Web Editor NEWThe main sample app for the Ruby on Rails Tutorial, 6th Edition
License: Other
The main sample app for the Ruby on Rails Tutorial, 6th Edition
License: Other
I am at chapter 11 of the whole book, the local part is okay, but when moving to the production site, when adding on the SendGrid to the production, things happened below:
2021-05-31T03:31:15.411568+00:00 app[web.1]: <h1>Sample App</h1>
2021-05-31T03:31:15.411569+00:00 app[web.1]: <p>Hi jessezhang,</p>
2021-05-31T03:31:15.411569+00:00 app[web.1]: <p>
2021-05-31T03:31:15.411569+00:00 app[web.1]: Welcome to the Sample App! Click on the link below to activate your account:
2021-05-31T03:31:15.411570+00:00 app[web.1]: </p>
2021-05-31T03:31:15.411570+00:00 app[web.1]: <a href="https://peaceful-lake-58934.herokuapp.com/account_activations/tYhSpsIOZoizx1tW4W7Kfg/edit?email=jessejunjing2%40163.com">Activate</a>
2021-05-31T03:31:15.411571+00:00 app[web.1]: </body>
2021-05-31T03:31:15.411571+00:00 app[web.1]: </html>
2021-05-31T03:31:15.411571+00:00 app[web.1]:
2021-05-31T03:31:15.411572+00:00 app[web.1]: ----==_mimepart_60b4588357a2f_92b1eb836e578698e8--
2021-05-31T03:31:15.411572+00:00 app[web.1]:
2021-05-31T03:31:15.412252+00:00 app[web.1]: I, [2021-05-31T03:31:15.412183 #9] INFO -- : [6e653373-0a7f-4b22-80e6-fd1e0405431e] Completed 500 Internal Server Error in 982ms (ActiveRecord: 31.5ms | Allocations: 6501)
2021-05-31T03:31:15.413372+00:00 app[web.1]: F, [2021-05-31T03:31:15.413300 #9] FATAL -- : [6e653373-0a7f-4b22-80e6-fd1e0405431e]
2021-05-31T03:31:15.413373+00:00 app[web.1]: [6e653373-0a7f-4b22-80e6-fd1e0405431e] Net::SMTPAuthenticationError (535 Authentication failed: account disabled
2021-05-31T03:31:15.413374+00:00 app[web.1]: ):
2021-05-31T03:31:15.413374+00:00 app[web.1]: [6e653373-0a7f-4b22-80e6-fd1e0405431e]
2021-05-31T03:31:15.413374+00:00 app[web.1]: [6e653373-0a7f-4b22-80e6-fd1e0405431e] app/models/user.rb:68:in `send_activation_email'
2021-05-31T03:31:15.413375+00:00 app[web.1]: [6e653373-0a7f-4b22-80e6-fd1e0405431e] app/controllers/users_controller.rb:30:in `create'
2021-05-31T03:31:15.415104+00:00 heroku[router]: at=info method=POST path="/users" host=peaceful-lake-58934.herokuapp.com request_id=6e653373-0a7f-4b22-80e6-fd1e0405431e fwd="47.241.19.216" dyno=web.1 connect=1ms service=990ms status=500 bytes=1891 protocol=https
I double-checked the code in my production.rb file, I think they are fine:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'peaceful-lake-58934.herokuapp.com' # Don't use this literally; use your local dev host instead
config.action_mailer.default_url_options = { host: host, protocol: 'https' }
ActionMailer::Base.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
authentication: :plain,
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
domain: 'heroku.com',
enable_starttls_auto: true
}
And I also checked several StackOverflow Q&As, it looks like the SendGrid add-on on Heroku is becoming hard to use recently(from when I am not sure). I then try to sign up by my own email on SendGrid, it is also failed, the SendGrid login page keeps telling me that I am not authorized and I should call the support(some advice like that).
Anyway, I guess I should let you(the author) know the situation.
Or is my assumption is wrong, or there are some fault steps in my code when learning your materials, I am not sure.
Anyway, I will keep learning this material and just ignore this part now.
Thanks again for the brilliant ruby on rails tutorial materials.
Currently, the version of minitest listed (5.11.3) for the Sample App in chapter 3.1 "Sample app setup" causes the following error message:
You have requested:
minitest = 5.11.3The bundle currently has minitest locked at 5.12.2.
Try runningbundle update minitest
If you are updating multiple gems in your Gemfile at once,
try passing them all tobundle update
By simply changing the specified minitest version in the Gemfile to 5.12.2 instead, and then proceeding with bundle install --without production
, the error is fixed.
I have encountered 2 problems when running rails s after saving the file below:
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
port ENV.fetch("PORT") { 3001 }
environment ENV.fetch("RAILS_ENV") { ENV['RACK_ENV'] || "development" }
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
preload_app!
plugin :tmp_restart
Error stating - [8620] ERROR: worker mode not supported on ruby on this platform. I overcame this error by commenting out the line - "workers ENV.fetch("WEB_CONCURRENCY") { 2 }"
I subsequently then get the following error message when I run rails s. It will only work if I change the port number to 3001 - "Only one usage of each socket address (protocol/network address/port) is normally
permitted. - bind(2) for "::1" port 3000 (Errno::EADDRINUSE)"
I have googled, but cannot find any satisfactory answers as to why this is happening.
The book was released in 2021, so I assume all the code is up to date. Do you know what is causing this issue please?
I am using windows 10 and using gem 'puma', '~> 5.0'
Hi there, when using the code in listing 6.27 I ran into a syntax error. The code you have in the tutorial is written as:
uniqueness: case_sensitive: false
I was able to fix the issue by using:
uniqueness: { case_sensitive: false }
which caused the tests to pass. I'm not sure if it's the difference between an update in Rails since when you first uploaded the tutorial or not, but I figured I'd let you know.
FYI. The draft version of 7th edition Listing 3.47 links to the Guardfile here, but the listings are different.
Namely, the require
statement. Just wanted to let you know.
Thanks for the new release.
I followed the readme and bumped into this error:
Webpacker can't find application.js in /Users/alex/Projects/sample_app_6th_ed/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
Precompiling the assets helped, so I think these line (or similar) needs to be added to the installation instructions:
rails assets:precompile
test/helpers/application_helper_test.rb
require 'test_helper'
class ApplicationHelperTest < ActionView::TestCase
test "full title helper" do
assert_equal full_title, FILL_IN
assert_equal full_title("Help"), FILL_IN
end
end
Above is the code in the book(Chapter6's final part which ask me to push the code to heroku), and I need to comment the require 'test_helper' and push it to heroku, otherwise the heorku site will crash.
Gemfile like below(guess it can serve some information to let you know my env):
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
gem 'active_storage_validations', '0.8.9'
gem 'bcrypt', '3.1.13'
gem 'bootsnap', '1.7.2', require: false
gem 'bootstrap-sass', '3.4.1'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'faker', '2.11.0'
gem 'htmlbeautifier'
gem 'image_processing', '1.9.3'
gem 'jbuilder', '2.10.0'
gem 'mini_magick', '4.9.5'
gem 'puma', '5.2.2'
gem 'rails', '6.1.3.1'
gem 'sass-rails', '6.0.0'
gem 'turbolinks', '5.2.1'
gem 'webpacker', '5.2.1'
gem 'will_paginate', '3.3.0'
group :development, :test do
gem 'byebug', '11.1.3', platforms: %i[mri mingw x64_mingw]
gem 'sqlite3', '1.4.2'
end
group :development do
gem 'listen', '3.4.1'
gem 'rack-mini-profiler', '2.3.1'
gem 'solargraph'
gem 'spring', '2.1.1'
gem 'web-console', '4.1.0'
end
group :test do
gem 'capybara', '3.35.3'
gem 'guard', '2.16.2'
gem 'guard-minitest', '2.4.6'
gem 'minitest', '5.11.3'
gem 'minitest-reporters', '1.3.8'
gem 'rails-controller-testing', '1.0.5'
gem 'selenium-webdriver', '3.142.7'
gem 'webdrivers', '4.6.0'
end
group :production do
gem 'aws-sdk-s3', '1.87.0', require: false
gem 'pg', '1.2.3'
end
.
.
.
By the way, the book is really helpful, thanks for your effort.
Best regards.
I am reading the 7th chapter about how to test submission with form, and there are two test cases below, and the confusing part is about when should I use follow_redirect! why the first case doesn't need this line, and the second one needs it? Thank you so much for helping.
require 'test_helper'
class UsersSignupTest < ActionDispatch::IntegrationTest
test 'invalid signup information' do
get signup_path
assert_no_difference 'User.count' do
post users_path, params: { user: { name: '',
email: 'user@invalid',
password: 'foo',
password_confirmation: 'bar' } }
end
assert_template 'users/new'
assert_select 'div#error_explanation'
assert_select 'div.alert.alert-danger'
end
test 'valid signup information' do
get signup_path
assert_difference 'User.count', 1 do
post users_path, params: { user: { name: 'Example User',
email: '[email protected]',
password: 'password',
password_confirmation: 'password' } }
end
follow_redirect! #It's all about This line!
assert_template 'users/show'
end
end
I noticed a rogue space in Listing 7.2, it is written as . debug_dump
instead of (I assume) .debug_dump
.
This is in the O'Reilly version of the tutorial.
The User
model has a feed
method that is currently implemented the following way:
# Listing 14.47: The final implementation of the feed
def feed
following_ids = "SELECT followed_id FROM relationships
WHERE follower_id = :user_id"
Micropost.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
end
# Listing 14.50: Using a join to make the feed.
def feed
part_of_feed = "relationships.follower_id = :id or microposts.user_id = :id"
Micropost.joins(user: :followers).where(part_of_feed, { id: id })
end
I think a slightly more elegant solution may be proposed here, for instance:
# User.rb
def feed
Micropost.appearing_in_feed_of(self)
end
# Micropost.rb
scope :appearing_in_feed_of, ->(user) do
where( user_id: user.following.select(:id))
.or(where user_id: user.id)
end
The following SQL query is produced by the code above:
SELECT "microposts".* FROM "microposts"
WHERE (
"microposts"."user_id" IN (
SELECT "users"."id"
FROM "users"
INNER JOIN "relationships"
ON "users"."id" = "relationships"."followed_id"
WHERE "relationships"."follower_id" = ?
)
OR "microposts"."user_id" = ?
)
ORDER BY "microposts"."created_at" DESC
As you can see, just like the solution currently used, the one proposed here also produces a single SQL query with subquery, but:
default_scope
that has been used earlierOR
with ActiveRecordMichael,
In the basic login chapter of the PDF book (published 01-31-21), the create action incorrectly logs in the user with log_in @user
whoever this should be log_in user
Thanks for the great resource
Hi Michael,
thanks for your book and the sample app!
I developed a twitter sample app while reading your book. Just checked my app and the Account
dropdown menu stopped working. I cloned your app and it's not working too:[ Nothing happens when you click the Account
button on the navigation bar. It seems like something is off with bootstrap
or jqueru
. There is a not found resource
error in the console.
Hoping you could help to resolve the issue
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.