LoadError: Could not load the ‘listen’ gem (Rails 5)

If you are on rails 5 and you are using the default config/environments/development.rb file it will have this line of code in there. config.file_watcher = ActiveSupport::EventedFileUpdateChecker This requires the gem listen. This threw me for a bit as I was doing a rails 4 upgrades to a rails 5 edit: Forgot to mention that if … Read more

Why Rails 5 uses ApplicationRecord instead of ActiveRecord::Base?

While it may seem the same in basic Rails applications, there actually is an important difference once you begin to use rails engines, plugins / gems or direct methods from ActiveRecord::Base. ActiveRecord::Base.include(MyFeatures) mixes in the features directly into ActiveRecord::Base and it is present there forever for all later uses of ActiveRecord::Base (it cannot be “unmixed”) … Read more

Rails 5, Rspec: Environment data not found in the schema

New Rails 5 command to generate binstubs: rails app:update:bin Allows me to run the solution as the error suggested: bin/rails db:environment:set RAILS_ENV=test Tip from @max comment: If you are using database_cleaner and this error keeps popping up then change your config to: DatabaseCleaner.clean_with( :truncation, except: %w(ar_internal_metadata) )

ActiveRecord OR query Hash notation

There are 5 options that could be considered as implementations of «Hash notation» (the last two are kinda hash-ish): With Ruby on Rails 5 you are able to do the following chaining using ActiveRecord::Relation#or method: Person.where(name: ‘Neil’).or(Person.where(age: 27)) Use where_values together with reduce. The unscoped method is necessary only for Rails 4.1+ to ensure default_scope … Read more

Why does Rails fails to boot with “Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)”?

What’s happening? Looks like you’ve upgraded sprockets. The later version(s) of sprockets require what’s called a manifest.js file. You don’t have one. You need to create one, and add in a few “directives”. Why do I need to do this? In the old version of sprockets, big assumptions were made about what assets to bundle/concatenate** … Read more

What is the use of secret_key_base in rails 4

The secret_token.rb file’s content includes a long randomized string which is used to verify the integrity of signed cookies (such as user sessions when people are signed into your web app). Documentation says: Use your existing secret_key_base from the secret_token.rb initializer to set the SECRET_KEY_BASE environment variable for whichever users run the Rails app in … Read more

What to use instead of `render :text` (and `render nothing: true`) in rails 5.1 and later?

The non-deprecated way is to use render :plain Rails Guide on Layouts and Rendering: 2.2.6 Rendering Text You can send plain text – with no markup at all – back to the browser by using the :plain option to render: render plain: “OK” Bonus Instead of render nothing: true (also removed), one should now use … Read more

Rails 5: how to use $(document).ready() with turbo-links

Rather than listen to the ready event, you need to hook in to an event fired by Turbolinks for every page visit. Unfortunately, Turbolinks 5 (which is the version that appears in Rails 5) has been re-written, and does not use the same event names as in previous versions of Turbolinks, causing the answers mentioned … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)