Rails: How do I create a custom 404 error page that uses the asset pipeline?

For Rails 4.1 I like this answer, add an asset type better; however I have not tried it. On Rails 4.0.8, these three references helped me: Dynamic error pages is the second reference in the question. This worked just fine for me. Custom error pages may have cribbed from the first reference, or the other … Read more

Rails, Devise, Rspec: Undefined method ‘sign_in’

Did you recently upgrade to RSpec 3 like I did? This is from the RSpec 3 documentation: Automatically Adding Metadata RSpec versions before 3.0.0 automatically added metadata to specs based on their location on the filesystem. This was both confusing to new users and not desirable for some veteran users. In RSpec 3, this behavior … Read more

Gem Vs Plugin Vs Engine in Ruby on Rails

Plugins as you knew them from Rails 2 (i.e. plugins under the vendor/plugins folder) were deprecated for Rails 3.2; support for it was completely removed in Rails 4. Now, there’s a concept of a “gamified plugin” where the plugins are essentially built as gems and can be shared across different Rails applications. But to answer … Read more

Option for Cascade Delete for References or On Delete

This should work create_table :childs do |t| t.references :parent, index: true, foreign_key: {on_delete: :cascade} t.string :name t.timestamps null: false end According to ActiveRecord::ConnectionAdapters::TableDefinition#references, if a hash is specified on the foreign_key option, it is directly passed down into the foreign_key method. source: foreign_key(col.to_s.pluralize, foreign_key_options.is_a?(Hash) ? foreign_key_options : {}) if foreign_key_options

Rails – Devise send user email after sign_up/create

Confirmation emails should be sent from the controller. It’s simple to override the Devise::RegistrationsController defaults. Create the file app/controllers/my_registrations_controller.rb (name this whatever you want) class MyRegistrationsController < Devise::RegistrationsController def create super if @user.persisted? UserMailer.new_registration(@user).deliver end end end Then in your routes: devise_for :users, :controllers => { :registrations => “my_registrations” }

Redis + ActionController::Live threads not dying

A solution I just did (borrowing a lot from @teeg) which seems to work okay (haven’t failure tested it, tho) config/initializers/redis.rb $redis = Redis.new(:host => “xxxx.com”, :port => 6379) heartbeat_thread = Thread.new do while true $redis.publish(“heartbeat”,”thump”) sleep 30.seconds end end at_exit do # not sure this is needed, but just in case heartbeat_thread.kill $redis.quit end … Read more

Missing production secret_key_base in rails

For local development Generate a secret using rails secret Method #1: Store this secret in your .bashrc or .zshrc see https://apple.stackexchange.com/questions/356441/how-to-add-permanent-environment-variable-in-zsh for Method #2: Use the dotenv Gem Once you have this gem installed, you then create a .env file in the root of your Rails app that does NOT get checked-into the source control. … Read more

Rails 4.0 Strong Parameters nested attributes with a key that points to a hash

My other answer was mostly wrong – new answer. in your params hash, :filename is not associated with another hash, it is associated with an ActiveDispatch::Http::UploadedFile object. Your last code line: def screenshot_params params.require(:screenshot).permit(:title, assets_attributes: :filename) is actually correct, however, the filename attribute is not being allowed since it is not one of the permitted … Read more