...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
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.
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...
...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...
...just upgraded to Bundler 10.0.10 you might get the following error when bringing up Rails: /usr/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 17 column 14 (Psych::SyntaxError...
...This is caused by Rails localization files (en.yml, de.yml, etc.) using symbols for various translation strings, and Bundler 10.0.10 defaults to a new YAML engine which cannot handle symbols.
Once Rails knows a given string is html_safe, it will never escape it. However, there may be times when you still need to escape it. Examples are some safe...
...to turn your string into an unsafe string to get the escaping love from Rails: embed = javascript_tag('var foo = 1337;') # This is an html_safe SafeBuffer embed.to_str # This...
...or from the public folder with javascript_include_tag. The subtle difference that tells rails how to build the path correctly is a single slash at the beginning of the...
...stylesheet in /assets you need to add it to the list of assets that Rails will precompile...
To reload a single-item association in Rails 5+, call #reload_ : post.reload_author In older Railses you can say post.author(true...
...want to uninstall newer ones): bundle _1.0.10_ -v Bundler version 1.0.10 An example is rails 3.2, which freezes bundler at version ~> 1.0: Bundler could not find compatible versions for gem...
In Gemfile: rails (~> 3.2) was resolved to 3.2.0, which depends on bundler (~> 1.0) Current Bundler version: bundler (1.13.6) You can solve this with: gem install bundler -v 1.0.10
...files at once. To activate this feature, set the multiple attribute: Or in a Rails view: <%= file_field_tag "images[]", multiple: true %> This works in IE10+. Make sure that the...
...incoming files into an array. Obviously this naming convention is not compatible with default Rails nested attribute setters, so you'll need to write a form model to adapt...
...code below is a rough equivalent to the simple_format helper that ships with Rails: function simpleFormat(str) { str = str.replace(/\r\n?/, "\n"); str = $.trim(str); if (str.length > 0) {
...str.replace(/\n\n+/g, ' '); str = str.replace(/\n/g, ' '); str = ' ' + str + ' '; } return str; } Unlike the Rails helper, this does not preserve whitespace. You probably don't care...
JavaScripts and CSS should be minified for production use. In Rails 3.1+ the asset pipeline will take care of this. Thus you're best off using an uncompressed version of...
...be easier and you will still get all the minification love once deployed. In Rails 2.3 and 3.0 you should at least embed external JavaScript libraries in minified form, using...
...false (intercepts invocation), whereas false&.class permits the invocation. &. might also remind you of Rails' Object#try. However, their scopes are different, and in Rails 4 nil-checking is only...
...route that only responds to a given format, here is how you do it: Rails 3 match 'sitemap.xml' => 'feeds#sitemap', :constraints => { :format => 'xml' }, :as => 'sitemap' Rails 2 map.sitemap 'sitemap.xml', :controller...
Katapult 0.3.0 brings Rails 5 and Ruby 2.5 support with a new design, plus a ton of smaller features, fixes and improvements. Features Generating a Rails 5.1.4 app on Ruby...
Remember how Rails 2 came with an awesome feature that broke all code using Time.now or Time.parse? This behavior is now the default for Rails 3. Disable it by adding...
Using Scenic, you can bring the power of SQL views to your Rails application without having to switch your schema format to SQL. Scenic provides a convention for versioning views...
SSHKit 1.9.0 might fail with the following error, when trying to deploy a Rail application. Upgrading the gem to version 1.21.0 fixed the issue. Traceback (most recent call last...
Katapult was an endeavor to dramatically speed up starting a new Rails application. However, it turned out to save less time than expected, while requiring more time for maintenance than...
...code antiquated. Nevertheless, its architecture may remain an inspiration on how to use the Rails generators programmatically...
view_context.helper_method('args') Rails 2 ApplicationController.helpers.helper_method('args') Also see How to use helper methods inside a model...
...be updating some of a form's fields via XHR. You can simply use Rails' fields_for to do things like this in your views (HAML here): - fields_for @user...
With Rails 4, Concerns have become the “official” solution to the big-models problem. However, there’s a fair amount of controversy about this topic in the community. Not everyone...
...problem of AR models becoming too big. In this talk we will see what Rails Concerns are and how can we use them to keep our models fit. More interestingly...
...these styles, and system will fail when passing it invalid arguments: system 'bundle exec rails server', '-p 3000' # fails and returns nil This is equivalent to running a command called...
...bundle exec rails" (including spaces in its filename). There is usually no such command anywhere on the $PATH. Note that you should prefer the 2nd approach (list of arguments instead...
When you need to use diff in either some Ruby code or your Rails app, use the differ gem. puts Differ.diff "foo", "boo" # => {"boo" >> "foo"} Usage There are several variants...