...migration_user.phone ) end end end Now the best idea is to test this in the rails sandbox (so your development data stay untouched): rails console --sandbox 2.4.1 :003 > DataMigration.new.run
...more unreadable to more attributes you delegate. Alternative to def_delegators When working with Rails, use delegate...
...:to =>...
class Post < ActiveRecord::Base belongs_to :topic delegate :title, :category, :to...
end Looks a lot like the above def_delegators call but behaves differently. Rails does not provide a pretty solution to this, but simply write a method for it...
Firefox 5.0.1, which we were using for most Rails 2.3 projects, does not run on Ubuntu 14.04 any more. Here is how to update affected projects. Update (or create) .firefox...
...run tests with Geordi, it will tell you how to install it. On a Rails 2 project: Update your Cucumber-related gems as described in Upgrading Cucumber and Capybara, including...
...print, if present requires interactive_editor, if present (basically makes vim available) loads .irbrc_rails if in Rails (e.g. for the Rails console) .irbrc_rails defines efind(email), which is...
...to find users by email requires hirb, if present set the prompt to your Rails app's name Of course you can put anything into these files...
...all styling inline, which means you'll have to do your styling inline. For Rails applications, you can use Roadie or premailer, which lets you keep your well-structured CSS...
...passive maintenance mode, we go with premailer: Include premailer in your Gemfile: gem 'premailer-rails' In your ApplicationMailer define the mailer layout: layout 'mailer' To get the mailer stylesheet (and...
Ubuntu 12.04 LTS x64, Ruby 1.8.7, Rails 2.13, PDFKit 0.5.4, Phusion Passenger Apache 2 I ran into this, when I started using passenger to deal with the Single Thread Issue...
...wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf sudo chmod +x /usr/local/bin/wkhtmltopdf Tell PDFKit where to find your wkhtmltopdf: Rails::Initializer.run do |config| require "pdfkit" config.middleware.use PDFKit::Middleware PDFKit.configure do |config| config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf' # <-- the fix...
...port and the username (default root) and password (default msandbox). When working on a Rails project, you need to paste all of that into your config/database.yml. Connecting to a sandbox...
...revert to the original Rubygems by saying gem uninstall slimgems #If you are using Rails 2.3.11 Rails 2.3.11 can also trigger this warning. Install 2.3.12+. After installation, you need to...
Rails has the handy controller method send_file which lets us download files easily. We can decide whether the file should be downloaded (disposition: 'attachment') or shown in the browser...
...only want to compile when needed. This card shows what will cause Webpacker (the Rails/Webpack integration) to compile your assets. When you run a dev server While development it is...
...call any helper that accesses asset paths (e.g. javascript_pack_tag or image_tag), Rails will compile your entire assets within its process before that helper returns. This will cause...
...following helper. def greeting message = ''.html_safe message << 'Welcome to ' message << content_tag(:span, Rails.env, class: 'greeting--location') content_tag :div, message, class: 'greeting' end That looks clumsy and is...
...say something like this? def greeting render_haml <<-HAML .greeting Welcome to %span.greeting--location = Rails.env HAML end It would be, and you can have it, too. You simply need to...
If you are using Angular and want something like Rails' simple_format which HTML-formats a plain-text input into paragraphs and line breaks, this directive is for you.
...like to split a Ruby array into pairs of two, you can use the Rails ActiveSupport method in_groups_of: >> [1, 2, 3, 4].in_groups_of...
...split a Ruby array into a given number of groups, you can use the Rails ActiveSupport method in_groups: >> [1, 2, 3, 4, 5, 6].in_groups...
Issue: You have an app using jsbundling-rails and esbuild. After deploy, the assets built by esbuild are missing in public/assets. Solution: Add app/builds to your git repo (by adding...
There are different ways to run rake: On Rails 4.1+ projects, you have Spring and its binstubs which dramatically improve boot-up time for Rake and similar. You need to...
rake is a function rake () ... Next, try running rake routes on a Rails 4.1+ project -- the 2nd time should be significantly faster. On older projects you should always...
...the need to enter user and password, you can say the following in any Rails 2 project: script/dbconsole -p In Rails 3 you can say: rails dbconsole -p
Provide a stable API for working with scopes across multiple versions of Rails, since Rails has a tradition of breaking details of its scope API every other release...
...for when you can use transactions: Transactions cannot be used for Selenium features, where Rails and test run in different processes and thus don't see changes within the transaction...
...different cleaning strategies I measured the runtime of different strategies using an average-sized Rails project (with MySQL): Cucumber RSpec Transaction 87.14, 86.65 10.20, 10.11
DETAIL: There is 1 other session using the database. This could be the rails server, rubymine and many more. Beside terminating the session connection manually you can also find...
...out the pid and kill the process. 1. rails db 2. SELECT * FROM pg_stat_activity; datid | 98359 datname | foo_development pid | 21633 usesysid | 16384 usename | username application_name | DataGrip...
To reload a single-item association in Rails 5+, call #reload_ : post.reload_author In older Railses you can say post.author(true...
I got this error when running Rails 2.3 tests for Rails LTS. More stacktrace: NoMethodError: undefined method `cache' for Gem:Module /vagrant/rails-2-3-lts-repository/railties/lib/rails_generator/lookup.rb:212:in `each' /vagrant/rails-2-3-lts-repository/railties/lib/rails_generator/lookup.rb:146:in `to_a...
...scenario, the code below lets you write this: Given my IP address is 188.174.117.205 Rails 3 Given /^my IP address is "(.*?)"$/ do |ip| ActionDispatch::Request.any_instance.stub(:remote_ip).and_return(ip...
Rails 2 You will need the following step definitions: Given /^my IP address is (\d+\.\d+\.\d+\.\d+)$/ do |ip| ApplicationController.stubbed_request_ip = ip end After do ApplicationController.stubbed_request...
...up 20160517112656 Migrate pages to page versions up 20160518112023 ********** NO FILE ********** When you tell Rails to roll back, it tries to roll back the latest change that was migrated. In...
...have the corresponding migration file for. Hence, it can not be rolled back and Rails aborts silently. This happens for example when you migrated on the master branch at some...
Before Rails 3.2.14, when supplying an invalid locale to I18n, it would fall back to its config.i18n.default_locale (which is :en by default). Eventually, this will be changed to raise...
...an error by default -- for now, it shows a deprecation warning. Since Rails 3.2.14 and 3.2.15 did not include security updates, you might not have applied them and probably now...