evilmartians.com

...building it yourself Also see the chapter "Owning your Stack" in the book Growing Rails Applications in Practice. Services Open-Source Maturity & Maintenance Certification Rubygems

blog.bigbinary.com

...posts"."user_id" = "users"."id" WHERE (posts.id > 10) Using includes usually works nicely, but Rails will apply some magic, as mentioned at the beginning of this card. This is subject...

...an alternative to PostgreSQL fulltext search A simple example with a GIN index in Rails for optimizing a ILIKE query

...at self.class.ancestors. For example: config.before do # stuff that_fancy_method if is_a? Spec::Rails::Example::ControllerExampleGroup # more stuff end Find out if you are in a spec that knows...

...s request and response, like helper specs or controller specs: if is_a? Spec::Rails::Example::FunctionalExampleGroup that_fancy_request_thing end Note that you should not check via something...

...is to to require all files in a specific diretory, using something like Dir.glob(Rails.root.join('lib/ext/**/*.rb')).each do |filename| require filename end However, this causes files to be required...

...behavior on different machines which are hard to debug. Simply add a .sort: Dir.glob(Rails.root.join('lib/ext/**/*.rb')).sort.each do |filename| require filename end Ruby 3 Ruby 3 Dir class sorts...

...does not apply to your "Background" steps How to set up database_cleaner for Rails with Cucumber and RSpec Before all in database transactions will fail

relishapp.com

...for example could be sped up more than 4 times by reusing a cached Rails application, and the tests for a video player we built could also be sped up...

Learn about Method#source_location. Look up a method like save! in the Rails API docs. The result should have a link to the source location on GitHub.

...monkey patches. When you add or change an initializer you need to restart your Rails server or console for the changes to be picked up. Only changes in app are...

When your Rails application offers downloading a bunch of files as ZIP archive, you basically have two options: Write a ZIP file to disk and send it as a download...

...Add zip_tricks to your Gemfile and bundle install. In your controller, include ZipTricks::RailsStreaming. You can then use the zip_tricks_stream method in controller actions to generated your...

Adding the asset cache directory to symlinked directories Popular asset managers for Rails are Sprockets and Webpacker. Both keep a cache of already compiled files that we're...

makandra Curriculum

Read (or re-read) the following chapters from our book Growing Rails Applications in Practice (it’s in our library): New rules for Rails Beautiful controllers Relearning ActiveRecord

Webpacker can automatically create an icon font from SVG files, which is really handy. When you're using the asset...

...prevent this, you need to add ->{ uniq } as second argument to has_many (below Rails 4 it is a simple option: has_many :xyz, :uniq => true). Example

...model. Prefer to use a form model like User::RegistrationForm. Read our book Growing Rails Applications in Practice for details. Here is a test for the User model that automatically...

...command line flag when opening an IRB: irb --nomultiline This also works on modern Rails when using rails console like so: rails console -- --nomultiline Option 2: Disable by default

...excludes quote characters so you can easily paste the secret into a Ruby string Rails can also generate secrets that can be used for secret_key_base: $ bin/rails secret 5693040b90b1b09d0a73364d950f15e3a9604403c8e81c6e5bb8b51d0981ef3bbde15a52bf5df41ac4974675bb8e31d69d03490dc11abd1086c873783d1be607

github.com

...ids on an ActiveRecord scope to pluck all the ids of the relation: # Modern Rails User.where("users.name LIKE 'Foo Bar'").ids # Rails 3.2+ equivalent User.where("users.name LIKE 'Foo Bar'").pluck...

# Edge rider equivalent for Rails 2+ User.where("users.name LIKE 'Foo Bar'").collect_ids

Don't insert table rows in a Rails database migration. This will break tests that expect that database to be empty and cause you all sorts of pain.

...cloned project. The reason is your environment.rb which is loaded for Raketasks and calls Rails.application.initialize! which in turn may/will evaluate classes. If one of those classes is tries to access...

...if you don't know which one handled the request you are looking for. Rails application logs usually live in /var/www/ /shared/log. Web server logs usually live in /var/www/ /log...

...multiple servers at the same time With a custom Capistrano task: CMD='zgrep -P "..." RAILS_ROOT/log/production.log' bundle exec cap production app:run_cmd See Capistrano 3: Running a command on...

# ActiveRecord 3.2+ was activated end Detect if a gem has been required Rails will automatically require all the gems in your Gemfile, unless you pass the require: false...

...option. When working on non-Rails project (such as a gem), nothing is required automatically. To detect if a gem has been required, use defined? on one of the modules...

expect(time1).to eq(time2) end Note for users of #end_of_day Rails extends Time with a method #end_of_day which returns the latest possible Time on...

...need to configure this if you're using system tests with modern versions of Rails. They do exactly the same

From Exploring ES6: Module imports are hoisted (internally moved to the beginning of the current scope). Therefore, it doesn’t...