Rails 4 Error R14 on Heroku (Memory Quota Exceeded)

If Papertrail is causing a problem, try a different add on. I’ve been using LogEntries without much of a problem. https://addons.heroku.com/#logging Also try to lower your Unicorn worker processes so it uses lower total memory. Instead of the default of 3 (per box/dyno), try 2. https://devcenter.heroku.com/articles/rails-unicorn#unicorn-worker-processes You can also run a memory profiler on your … Read more

What is the best way to use Redis in a Multi-threaded Rails environment? (Puma / Sidekiq)

You use a separate global connection pool for your application code. Put something like this in your redis.rb initializer: require ‘connection_pool’ REDIS = ConnectionPool.new(size: 10) { Redis.new } Now in your application code anywhere, you can do this: REDIS.with do |conn| # some redis operations end You’ll have up to 10 connections to share amongst … Read more

What does before_action returning false do in Rails 4?

before_action (formerly named before_filter) is a callback that is performed before an action is executed. You can read more about controller before/after_action. It is normally used to prepare the action or alter the execution. The convention is that if any of the methods in the chain render or redirect, then the execution is halted and … Read more

can’t connect localhost:3000 ruby on rails in vagrant

The solution is running the code below to start your server: rails s -b 0.0.0.0 I found this solution from another post about same problem. The answerer said ‘You’ll want to make sure that the server is binded to 0.0.0.0 so that all interfaces can access it.” I hope this post helps people who encounter … Read more

before_destroy callback not stopping record from being deleted

In Rails 5 you have to throw :abort otherwise it won’t work. (even returning false) Also, you should add prepend: true to the callback, to make sure it runs before the dependent: :destroy on the parent models. Something like this should work: class Something < ApplicationRecord before_destroy :can_destroy?, prepend: true private def can_destroy? if model.something? … Read more

ActiveRecord::AdapterNotSpecified database configuration does not specify adapter

For you app to work locally you need to: Install Postgresql on your machine Create a database for your development needs (let’s call it my_app_development) Change your database.yml to: default: &default adapter: postgresql encoding: unicode # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: 5 development: <<: *default database: my_app_development run … Read more