What does inverse_of do? What SQL does it generate?

From the documentation, it seems like the :inverse_of option is a method for avoiding SQL queries, not generating them. It’s a hint to ActiveRecord to use already loaded data instead of fetching it again through a relationship. Their example: class Dungeon < ActiveRecord::Base has_many :traps, :inverse_of => :dungeon has_one :evil_wizard, :inverse_of => :dungeon end class … Read more

Ruby on Rails production log rotation

Option 1: syslog + logrotate You can configure rails, to use the systems log tools. An example in config/environments/production.rb. # Use a different logger for distributed setups config.logger = SyslogLogger.new That way, you log to syslog, and can use default logrotate tools to rotate the logs. Option 2: normal Rails logs + logrotate Another option … Read more

warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777

You will need to have root access to do this. If you aren’t already the administrative user, login as the administrator. Then use ‘sudo’ to change the permissions: sudo chmod go-w /usr/local/bin Obviously, that will mean you can no longer install material in /usr/local/bin except via ‘sudo’, but you probably shouldn’t be doing that anyway.

How do I ignore the authenticity token for specific actions in Rails?

Rails 5.2+ You can use the same skip_before_action method listed below or a new method skip_forgery_protection which is a thin wrapper for skip_before_action :verify_authenticity_token skip_forgery_protection Rails 4+: # entire controller skip_before_action :verify_authenticity_token # all actions except for :create, :update, :destroy skip_before_action :verify_authenticity_token, except: [:create, :destroy] # only specified actions – :create, :update, :destroy skip_before_action :verify_authenticity_token, … Read more

Heroku/devise – Missing host to link to! Please provide :host parameter or set default_url_options[:host]

You need to add this to your environment.rb config.action_mailer.default_url_options = { :host => ‘localhost’ } Make sure you change host to your production url and keep it localhost for development. This is for the mailer, it needs a default email to send out notices such as confirmations etc… You should check the logs on the … Read more

rake db:schema:load vs. migrations

Migrations provide forward and backward step changes to the database. In a production environment, incremental changes must be made to the database during deploys: migrations provide this functionality with a rollback failsafe. If you run rake db:schema:load on a production server, you’ll end up deleting all your production data. This is a dangerous habit to … Read more