...the standard configuration, though, it does not interpret the escape sequences used in the rails logfiles. To enable this type: less -R my_logfile.log You can also have an alias to...

There is a nasty bug in all version of Rails 2 and some versions of Rails 3.x where two chained scopes with hash conditions on the same attribute would...

...what a user may see or change. Workaround If you are using an affected Rails version and cannot switch to a fixed version, you can use this manual workaround.

...for that. The reason why you never had to write this line is that Rails does this for you when it boots the environment. That also means that if you...

...have an embedded Rails app in your spec folder (like has_defaults), and you boot its environment, it should call Bundler.require for you and you don't need to require...

...can remove conditions, order, etc by using the unscope method. It is available on Rails 4+. Examples Consider an exemplary User class as follows. For the examples below, we will...

...scope of any constraints. users.unscoped ^ SELECT "users".* FROM "users" While unscope was introduced with Rails 4, the unscoped method has been around since Rails...

github.com

...performance due to the cost of reindexing. Minidusen is currently compatible with MySQL, PostgreSQL, Rails 3.2, Rails 4.2 and Rails 5.0. Basic Usage Our example will be a simple address...

...Note that #origin_class it roughly equivalent to the blockless form of #unscoped from Rails 3.2+, but it works consistently across all Rails versions. #unscoped does not exist for Rails...

...and is broken in Rails...

Submit buttons in Rails come with a useful option :disable_with which will disable the button when clicked and change its label to something like "Please wait...". An annoying side...

...is to re-enable the submit button before leaving the page. This works in Rails 3: $(window).unload(function() { $.rails.enableFormElements($($.rails.formSubmitSelector...

The ActionDispatch module of Rails gives you the helper method flash to access the flash messages in a response. describe PostsController, type: :request do describe 'update' do it 'shows a...

apidock.com

t.column_name, :string t.remove :first_name t.remove :last_name t.rename :cool, :awesome end Rails 2 caveats Rails 2 does not understand the extra options hash but seems to build...

...only created when you rename columns. For other operations such as add and remove Rails 2 will still give you single ALTER statements. More See RobinWu's APIdock comment for...

...they won't change their mind. [1] We are not talking about the the Rails session cookie here, though it often is a session cookie...

semaphoreci.com

task :script, roles: :app, only: { primary: true } do run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rails runner 'ScriptRunner.go'" end becomes desc 'Run script'

on primary :app do within current_path do with rails_env: fetch(:rails_env, 'production') do execute :bundle, 'exec', "rails runner 'ScriptRunner.go'" end end end end

...helps to modify the Accept-Language in tests. Here is an example for a Rails application with Cucumber integration tests: class ApplicationController OVERRIDE_HTTP_ACCEPT_LANGUAGE = nil def accept_language...

encoding: utf8 username: root password: secret Note if you're on an old Rails version If you're using a Rails version less than 3.1 (e.g. 2.3.x...

...Newer versions no longer include the ActiveRecord adapter (which is part of ActiveRecord since Rails .1). So your Gemfile should say:

...tokens or CSP nonces. We have deprecated Rack::SteadyETag. We instead recommend reconfiguring your Rails app so two requests to the same resource produce the same HTML for a given...

Rails includes milliseconds in Time / DateTime objects when rendering them as JSON: JSON.parse(User.last.to_json)['created_at'] #=> "2001-01-01T00:00:00.000+00:00" In RSpec you might want...

...have to run a separate process. # You'll also benefit from code reloading. if Rails.env.development? require 'sidekiq/testing' Sidekiq::Testing.inline!

...byebug 11.1.3 (the most recent version at time of writing) when using it with Rails 6 and it's new autoloading component, zeitwerk. There already is a issue for that...

You have to specify the environment with -e env_name or RAILS_ENV=env_name if you want to run a script on the server. at Rails 2 it's...

bundle exec script/runner -e env_name path/to/script.rb argument1 argument2 ... at Rails 3 it's rails runner RAILS_ENV=env_name bundle exec rails runner path/to/script.rb argument1 argument2...

...OVER() AS full_count FROM (/* some complicated subquery */) posts LIMIT 20 OFFSET 100; In Rails with will_paginate you might use it like this: posts = scope_complicated_scope.select('posts.*, COUNT(*) OVER() AS...

User.active.to_sql Rails 2 Use either the Edge Rider or fake_arel gem to get #to_sql backported to Rails 2. If you don't want to use...

...a gem for this, you can do this with vanilla Rails 2: User.active.construct_finder_sql...

...block where you define replacements (as you already know). This issue applies to both Rails 2 (with rails_xss) as well as Rails 3 applications. Here is a fix to...

...html_safe.gsub(/(f)/) { puts $1; 'b' } f => "boo" Why? This is because of the way rails_xss implements "unsafe" methods: # vendor/plugins/rails_xss/lib/rails_xss/string_ext.rb UNSAFE_STRING_METHODS = [ ..., "gsub",...

for unsafe_method in UNSAFE...

makandra dev

...Commit using a story title from Pivotal Tracker geordi con[sole] [TARGET] # Open a Rails console locally or on a Capistrano deploy target geordi cu[cumber] [FILES] # Run Cucumber features...

...PATH # Optimize .png files geordi ra[ke] TASK # Run a rake task in several Rails environments geordi re[move-executable-flags] # Remove executable-flags from files that should not be...

Why is it often fine to memoize instance methods? Resources Speeding up Rails with Memoization 4 Simple Memoization Patterns in Ruby (And One Gem)

website_sizer = WebsiteSizer.new website_sizer.size_of('https://makandra.com') # => 27448 website_sizer.size_of('https://railslts.com') # => 2145364 You can use any library to perform the actual HTTP request. The class should...

If your rails application is unable to send mails, it might be useful to debug your settings using the rails console. Here is a snippet that shows the current settings...