...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...

...installing Bundler 1.1 you will get the following warning when running tests: WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is called...

...To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile The warning is misleading because it has nothing to do with moving cucumber-rails into...

Rails' params hash contains any request parameters (URL parameters or request payload) as well as routing parameters like :controller, :action, or :id. To access only URL parameters, use request.query_parameters...

makandra dev

Have you ever mistaken one Rails environment for another? The attached helper will help you to never do it again. Save the attached file to app/helpers/ and use the widget...

...in your layout like this: %body = rails_env_widget unless Rails.env.production? It'll render a small light gray box in the top left corner of your screen, containing the current...

Please don't use the horrible datetime_select helper. It has a terrible UI. Always prefer to use a visual...

markembling.info

Using uncountable resources is not recommended as it breaks Rails' magic, e.g. when using form_for. You'll always be better off using simple pluralizable resources. Rails automatically creates path...

...will refer to the show action: /sheep/:id. Solution As the linked article states, Rails creates a special _index_path for this scenario. Thus, you can simply call:

dusen 0.4.8 and edge_rider 0.2.3 no longer depend on Rails (they still depend on ActiveRecord). That means you can use them e.g. with Sinatra...

There are a few ways to access view helpers from the Rails console. The easiest way is the helper shortcut: helper.translate 'i18n.string' helper.your_helper_method If the desired helper renders...

...a view template, you need this setup: view_paths = Rails::Application::Configuration.new(Rails.root).paths["app/views"] av_helper = ActionView::Base.new(view_paths).extend YourHelperModule av_helper.your_helper_method

guides.rubyonrails.org

Starting from 4.1, Rails automatically detects the inverse of an association, based on heuristics. Unfortunately, it does not seem to notify you when it fails to infer the :inverse_of...

github.com

Rails 5 will introduce ActiveRecord::Relation#or. On Rails 4 and 3.2 you can use the activerecord_any_of gem which seems to be free of ugly hacks and nicely...

After starting the Rails server in a freshly generated Rails 3.1 project you could see an error message such as /usr/lib/ruby/gems/1.8/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime...

The Ruby on Rails security list archive can be found here: http://groups.google.com/group/rubyonrails-security You can subscribe to this mailing list without a Google account by pasting this URL into...

Rails 4 introduced raising an error on pending migrations. This is most annoying when you are crafting a migration but need to play with your application to figure out how...

...RVM on a Mac and cannot enter 8+ bit characters on an IRB or Rails console, you are missing the readline package. You will need to re-install your Ruby...

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...

This card needs to be updated for Rails 3+. Since there is no --debugger flag you need to run: rdebug script/runner lib/scripts/something.rb That will open an debugging IRB right away...

Install libreadline: sudo apt-get install libreadline-dev Reinstall the ruby and tell rvm where to find readline

Put the following into config.ru in your Rails root folder: # Require your environment file to bootstrap Rails require ::File.dirname(__FILE__) + '/config/environment' # Dispatch the request run ActionController::Dispatcher.new Otherwise, your Rails...

In FactoryBot factories, Rails' file_fixture is not available by default. To enable it, include a support module from rspec-rails: FactoryBot::SyntaxRunner.include(RSpec::Rails::FileFixtureSupport) That includes ActiveSupport::Testing...

iana.org

...decide to open a file directly instead of having to save it first. For Rails >= 3.2 Simply put your mime types in config/initializers/mime_types.rb. send_file will take care of everything...

For Rails < 3.2 Put your mime types in config/initializers/mime_types.rb. Additionally, tell send_file to use them (for example like this): file = @attachment.file.path file_extension = File.extname(file)[1..-1]

See our new comprehensive guide to upgrading every Rails 2 version ever...

See our new comprehensive guide for upgrading every Rails 2 version ever...

Today I learned that Ruby on Rails has shipped with a built-in slug generator since Rails 2.2: > "What Up Dog".parameterize => "what-up-dog" > "foo/bar".parameterize => "foo-bar"

...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...