Michael Hartl Ruby Section 5.1 - ruby-on-rails

I'm following Hartl's Ruby Tutorial. I'm on the beginning of chapter 5.
The instructions are to add an image ('rails.png') via
<%= link_to image_tag("rails.png", alt: "Rails logo"),
'http://rubyonrails.org/' %>
to the home page at: app/views/static_pages/home.html.erb
The image is downloaded via
$ curl -O http://rubyonrails.org/images/rails.png
$ mv rails.png app/assets/images/
However I am receiving an error on the asset precompile. I have no context on how to go about fixing this. So if there's extra info necessary to help solve this problem, let me know so I can add it!
This is the text of the error page of localhost:3000.
Sprockets::Rails::Helper::AssetNotPrecompiled in
StaticPagesController#home Asset was not declared to be precompiled
in production. Add Rails.application.config.assets.precompile += %w(
rails.png ) to config/initializers/assets.rb and restart your
server
Extracted source (around line #350): def
raise_unless_precompiled_asset(path)
raise Helper::AssetNotPrecompiled.new(path) unless precompiled?(path)
end
end
end
Edit : Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'bcrypt', '3.1.7'
gem 'faker', '1.4.2'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.0'
gem 'fog', '1.36.0'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '2.11.1'
end

I've encountered similar issue a while ago and I've fixed it by adding .png files to precompiled assets. Just try updating your config/application.rb file with following line:
config.assets.precompile += %w(.png)
Please remember about re-starting your Rails server afterwards ;)

Related

when use "heroku run rails test ", I got error "add `gem 'rails-controller-testing'` to your Gemfile" , and it's already added to my gemfile

I'm creating a new rails application, and I'm working on the registration system, based on "rails tutorial" book, but I got a problem, when I run
rails test
on my local machine for my rails app, I got no errors
but when push the app to heroku, and then run
heroku run rails test
I got this error
Error:
UsersSignupTest#test_valid_signup_information:
NoMethodError: assert_template has been extracted to a gem. To continue using it,
add `gem 'rails-controller-testing'` to your Gemfile.
test/integration/users_signup_test.rb:25:in `block in <class:UsersSignupTest>'
this is my gemfile
source 'https://rubygems.org'
ruby "2.5.1"
gem 'rails', '5.1.4'
gem 'bootstrap-sass', '3.3.7'
gem 'bcrypt', '3.1.12'
gem 'puma', '3.9.1'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.7.0'
gem 'carrierwave', '~> 0.11.2'
group :development, :test do
gem 'sqlite3', '1.3.13'
gem 'byebug', '9.0.6', platform: :mri
end
group :development do
gem 'web-console', '3.5.1'
gem 'listen', '3.1.5'
gem 'spring', '2.0.2'
gem 'spring-watcher-listen', '2.0.1'
end
group :test do
gem 'rails-controller-testing', '1.0.2'
gem 'minitest', '5.10.3'
gem 'minitest-reporters', '1.1.14'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
end
group :production do
gem 'pg', '0.18.4'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
any solutions please, knowing that I'm still newbie :)

Deploying Rails App with webpack to heroku

I created my rails with this template that included webpack. But i still wrote my javascript code in app/assets/javascript. Now I am trying to deploy my app to heroku and it keeps failing. I get this error
remote: /tmp/build_6f0656280cbbda40c5832ccb79fc1783/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/rubygems_integration.rb:432:in `block in replace_bin_path': can't find executable webpack for gem webpacker (Gem::Exception)
The main error seems to be "cant find executable webpack for gem webpacker". I have no idea how to solve it. This is my gemfile
source 'https://rubygems.org'
ruby '2.3.5'
gem 'figaro'
gem 'jbuilder', '~> 2.0'
gem 'puma'
gem 'rails', '5.1.4'
gem 'redis'
gem 'cloudinary'
gem 'carrierwave', '~> 1.2'
gem 'rails_admin', '~> 1.2'
group :production do
gem 'pg', '~> 0.20'
end
gem 'autoprefixer-rails'
gem 'bootstrap-sass'
gem 'jquery-rails'
gem 'font-awesome-sass'
gem 'sass-rails'
gem 'simple_form'
gem 'turbolinks', '~> 5.0.0'
gem 'coffee-rails'
gem 'uglifier'
gem 'webpacker'
gem 'devise'
gem 'ransack'
gem 'trix'
gem "letter_opener", group: :development
group :development do
gem 'web-console', '>= 3.3.0'
gem 'sqlite3'
end
group :development, :test do
# gem 'binding_of_caller'
# gem 'better_errors'
gem 'pry-byebug'
gem 'pry-rails'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
Breaking changes in 3.3.0
https://github.com/rails/webpacker/blob/master/CHANGELOG.md#330---2018-03-03
bundle exec rails webpacker:binstubs

How to completely remove webpack and all its dependencies from Rails App

I created my rails with this template that included webpack, I still write my javascript code in app/assets/javascript. I am trying to deploy my app to heroku and it keeps failing, I get this error
"remote:
/tmp/build_6f0656280cbbda40c5832ccb79fc1783/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/rubygems_integration.rb:432:in
`block in replace_bin_path': can't find executable webpack for gem
webpacker (Gem::Exception)"
I have tried lots of solutions but still cant get my app deployed to Heroku. I want to know how to completely delete webpack and all its depencies from my app since it was not even useful to my app
source 'https://rubygems.org'
ruby '2.3.5'
gem 'figaro'
gem 'jbuilder', '~> 2.0'
gem 'puma'
gem 'rails', '5.1.4'
gem 'redis'
gem 'cloudinary'
gem 'carrierwave', '~> 1.2'
gem 'rails_admin', '~> 1.2'
group :production do
gem 'pg', '~> 0.20'
end
gem 'autoprefixer-rails'
gem 'bootstrap-sass'
gem 'jquery-rails'
gem 'font-awesome-sass'
gem 'sass-rails'
gem 'simple_form'
gem 'turbolinks', '~> 5.0.0'
gem 'coffee-rails'
gem 'uglifier'
gem 'webpacker'
gem 'devise'
gem 'ransack'
gem 'trix'
gem "letter_opener", group: :development
group :development do
gem 'web-console', '>= 3.3.0'
gem 'sqlite3'
end
group :development, :test do
# gem 'binding_of_caller'
# gem 'better_errors'
gem 'pry-byebug'
gem 'pry-rails'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
remove bin/webpackor run bundle exec rake rails:update:bin
remove config/webpacker.yml
remove config/webpack
remove app/javascripts
remove config.webpacker.check_yarn_integrity = false from config/{development, test, production}.rb
verify that you don't have webpacker in your gemfile and run bundle install or bundle clean
imho, don't create your rails app with generators (unless it's your own)

Rails Elastic Beanstalk connection time out - puma server

I have searched over the web and stackoverflow but could not get this right.
I have a rails app and deployed to elastic beanstalk. The health is ok and green but the url is not working. It waits a little while and the page says connection time out.
when I type eb open
gives an error;
ERROR: OSError :: [Errno 10] No child processes
Could not figure out why this is happening.
When I eb deploy
INFO: Environment update is starting.
INFO: Deploying new version to instance(s).
INFO: Environment health has transitioned from Ok to Info. Application update in progress on 1 instance. 0 out of 1 instance completed (running for 4 seconds).
INFO: New application version was deployed to running EC2 instances.
INFO: Environment update completed successfully.
Can be a problem with load balancers? Where can I see if my database is created/migrated?
Here what I see error messages:
Gem file;
source 'https://rubygems.org'
gem 'rails', '4.2.0'
gem 'json', '~> 1.8.2'
gem 'bcrypt', '3.1.7'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'carrierwave'
gem 'rmagick'
gem 'fog-aws'
#gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.2' #it is added to new Rails applications by default.
gem 'dropzonejs-rails'
gem 'figaro'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
#gem 'jquery-ui-rails'
#//= require turbolinks TO ASSETS gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
gem 'wicked'
gem 'geocoder'
gem "mailboxer"
gem 'toastr-rails'
#gem "select2-rails"
gem 'jquery-cookie-rails'
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma'
end
Changing config.force_ssl = true to false fixed it for me

why is my rails server logging everything twice?

my rails server seems like it is logging everything twice, not sure what is going on here, what should I do to investigate this ?
my gemfile
source 'https://rubygems.org'
ruby '2.1.0'
gem 'rails', '4.0.1'
gem 'haml-rails'
gem 'pg', '~> 0.17.1'
gem 'redis'
gem 'redis-namespace'
gem 'thin', '~> 1.6.1'
gem 'rabl'
gem 'underscore-rails'
#assets
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'foundation-rails'
gem 'font-awesome-rails'
#javascript
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 1.2'
gem 'angularjs-rails', '~> 1.2.7'
gem 'ngmin-rails', '~> 0.4.0'
#user auth
gem 'devise', '3.0.0'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'uuidtools'
#misc tools
gem 'twitter'
#heroku
gem 'rails_12factor'
group :development, :test do
gem 'capybara-webkit', github: 'thoughtbot/capybara-webkit', branch: 'master'
gem 'rspec-rails', '~> 2.14.1'
gem 'factory_girl_rails', '4.2.1'
gem 'mocha', '~> 1.0.0'
gem 'pry'
gem 'pry-debugger'
gem 'quiet_assets'
gem 'parallel_tests'
gem 'zeus-parallel_tests'
gem 'guard-rspec'
gem 'rb-fsevent'
end
group :development do
gem 'guard-livereload'
gem 'rack-livereload'
gem 'better_errors'
gem 'terminal-notifier-guard'
end
group :test do
gem 'launchy', '>= 2.1.2'
gem 'capybara', '>= 1.1.3'
gem 'database_cleaner', '~> 1.2.0'
gem 'zeus', :require => false
gem 'shoulda-matchers'
gem 'pdf-inspector'
gem 'selenium-webdriver'
gem "mock_redis", "~> 0.11.0"
end
In my case this was caused by the rails_12factor gem. This gem adds the rails_stdout_logging gem which sends the logs to standard output. This can be useful in a production environment but not in development when Rails already does it by default.
https://github.com/heroku/rails_12factor#rails-4-logging
The solution is to only add this gem in production:
gem 'rails_12factor', group: :production
Have a look at this issue
Try adding the following code to you config/application.rb
if Rails.env.development?
# Don't log to STDOUT, by default rails s will handle it
config.logger = Logger.new('/dev/null')
else
# Don't log to file, sending everything to unicorn file.
config.logger = Logger.new(STDOUT)
end
Do you have your logger set to anything in either config/application.rb or config/environments/development.rb?
If nothing, try adding this line to config/environments/development.rb:
config.logger = Logger.new('/dev/null')
I had success with this in development.rb:
config.logger = ActiveSupport::Logger.new('/dev/null')

Resources