...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...
...images, this slows down development response times. You can fix that by defining a Rails route like this: if Rails.env.development? scope format: true, constraints: { format: /jpg|png|gif/ } do
...require to require_relative where I loaded RSpec factories in Cucumber's env.rb (the Rails application root is no longer in the load path by default) replacing the old debugger...
...to your Gemfile. iconv is a part of Ruby that was removed in 2.0. Rails 3 seems to depend on it. All the pain with magic # encoding: utf-8 comments...
...go, all you need to do is prefix every command with zeus. That means rails server becomes zeus server, rails console becomes zeus console, and so on. From the Github...
Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second. Requirements: OS X 10.7+ or Linux...
...it will look like this: >> Socket.gethostname => "happycat" That should work right away for your Rails application. For plain Ruby, you first need to do: require 'socket'
...often is) different from the host that a user is requesting in their current Rails session (request.host). Also keep in mind that hostname might give you the FQDN depending on...
...list like this: ----- Passenger processes ----- PID VMSize Private Name ------------------------------- 671 112.9 MB 95.5 MB Rails: /opt/www/project1/current 707 79.4 MB 60.5 MB Rails: /opt/www/project2/current 1094 88.1 MB 69.3 MB Rails: /opt/www/project3/current...
...MB 62.6 MB Rails: /opt/www/project4/current 1269 72.9 MB 55.6 MB Rails: /opt/www/project5/current
Let's say you need to revert a migration that happened a while back. You'd create a new migration...
You don't need a Rails application to use Sass. Even when you're working on a static site you can generate your CSS through Sass. Install Sass with sudo...
...gitignore to not exclude public/stylesheets/*.css, since stylesheets aren't being generated automatically without Rails (this would bite you after a deploy). Instead exclude .sass-cache, which will be created...
In specs, the session never persists but is always a new object for each request. Data put into the session...
In Rails 7.1 it has become possible to annotate partials with the locals they expect: # partial _user_name.erb <%# locals: (user:) %> <%= user.name %> # view <%= render 'user_name' %> <%# this raises an ArgumentError %> Unfortunately, when...
...temporarily remove the annotation to see the correct error. Niklas opened an issue in rails, a fix is merged and will arrive in Rails >7.2.2.2 and...
Any 404 error that is caused by something not found in your Rails app will render a nice message using your default layout. Similarly, you may catch and...
...is a MongoDB adapter for Ruby. We've forked it so it works for Rails 2.3.x applications running on Ruby 1.9. [1] makandra/mongomapper is based on the "official" rails2...
...it, add this to your Gemfile: gem 'mongo_mapper', :git => 'git://github.com/makandra/mongomapper.git', :branch => 'rails2' [1] The last version to be compatible with Rails 2 was 0.8.6: While there are...
...on how we make our app(s). In the beginning, there was the monolithic Rails app in the standard way with 100+ models and their many corresponding controllers and views...
...one via API. Our newest project is a single “app” made up of several Rails engines. We have found that this strikes a great balance between the (initial) straightforwardness of...
Last week saw a security issue with rails 2.3 that required a fix. While an official patch was provided, the 2.3 branch is no longer maintained. So we forked it...
...but they are not very easily discoverable.) To use our fork, change the gem "rails"... line in your Gemfile to this: gem 'rails', :git => 'https://github.com/makandra/rails.git', :branch...
Under certain (unknown) circumstances, Rails will give localized files an invalid content-type in the Response header. For me, after requesting corporate_information and rendering corporate_information.de.html.haml, Rails sent a content...
...topic that offer workarounds, but none solved it for me. The issue occurred with Rails...
When writing Rails migrations to convert a string column to an integer you'd usually say: change_column :table_name, :column_name, :integer However, PostgreSQL will complain: PG::DatatypeMismatch: ERROR...
...led me to the solution: I had to write has_many placeholder.to_sym. When Rails can't find an association, make sure it's defined as symbol Seemingly, that's...
...a bug in Rails...
The ActionMailer in Rails 2 depends on a buggy version of TMail, which sometimes inserts a blank line into the mail header when sending a mail to multiple recipients. This...
...mail through an MTA like Exim, it will fix this for you. Fix for Rails if you don't have an awesome MTA TMail is no longer maintained. The bug...
Ever wondered how Rails talks to itself in a Cucumber feature? In Rails 3 you can do it like this: def rack_env(path) { "rack.input" => {}, "PATH_INFO"=>"#{path}", "REQUEST_METHOD...
end request = rack_env('/users/new') response = Rails.application.call(request) status, headers, body = response puts status # e.g. 200 puts headers.inspect # hash of headers puts body.body # html of response body
See this Railscast. Basically you can simply write views like index.xlsx.erb: ID Name Release Date Price <% @products.each do |product| %> <%= product.id %> <%= product.name %> <%= product.released_on %> <%= product.price %> <% end %> This approach may help us...
...it has always worked: NoMethodError: undefined method `allow_value' for # This is due to Rails 4.1 (specifically, Spring) revealing a weak point of shoulda-matchers -- jonleighton explains why. Solution
...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...
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...