.sort_by(&:last) .to_h end end Just paste that snippet into a Rails console and use #count_by now! Usage examples Number of email addresses by domain: > User.all.count...

...Article.all.count_by &:brand Note that the last simple example can also be achieved with Rails internals: Article.group(:brand).count. This translates to SQL, so it executes fast. However, grouping is...

github.com

Params are tricky Testing for request params is a little tricky because Rails hides details about how HTTP works. In particular GET requests encode their params in the URL...

Rails Active Support provides some helpful methods for calculating times and dates, like Duration#ago or Duration#from_now. But beware when using those, because they wont give...

...timezone unaware. Moreover, you have to be aware that ActiveSupport::TimeWithZone does not use Rails.application.config.active_record.default_timezone, which you need to define, even if you only use your local timezone, but...

makandra dev

# Redis db#1 is used for development. db_number = 1 if rails_env == 'test' normalized_test_number = [ENV['TEST_ENV_NUMBER'].to_i, 1].max db_number += normalized...

end db_number end def port case rails_env when 'staging' # when 'production' # else 6379 # default Redis port end end def rails_env defined?(Rails) ? Rails.env : ENV['RAILS...

When a user shares your content, a snippet with title, image, link and description appears in her timeline. By default...

...load the dump successfully, i.e. restore data for all the tables it contained (including Rails' schema_migrations). However, it would not remove any extra tables that were not part of...

makandra dev
github.com

Generating a project README Finally: Support for modelling associations between models in your application model! Example: # lib/katapult/application_model.rb

github.com

quiet_assets helps with disabling asset pipeline log messages in the development log. When the gem is added, asset pipeline...

blog.rubybestpractices.com

class Errormaster CoffeeIsOut = Class.new(StandardError) # is prettier than class CoffeeIsOut < StandardError; end end Reference such an error class with Errormaster...

robots.thoughtbot.com

We are changing our name from Hoptoad to Airbrake. You see, some folks much larger than us reached out and...

pluginaweek.org

Now allows to list transition paths from and to arbitrary states.

gurge.com

How to write to the db 27,000 times in 24 seconds instead of 9 minutes.

opensoul.org

Sometimes, you just need to shoot from the hip…or deploy your local changes without committing them. Put this snippet...

avdi.org

When rendering a partial with the :collection option, you are automatically provided with a counter variable inside the partial template...

blog.jcoglan.com

Terminus is a Capybara driver where most of the driver functions are implemented in client-side JavaScript. It lets you...

apidock.com

You can now add an :inverse_of option to has_one, has_many and belongs_to associations.... Without :inverse_of...

github.com

Try our Apify gem which solves many problems you will be having.

github.com

Cerberus is a lightweight and easy-to-use Continuous Builder software for Ruby. It could be run periodically from a...

github.com

Consent is an access control abstraction layer for ActionController. It lets you restrict access to actions across your application using...

github.com

LaterDude is a small calendar helper with i18n support

pathf.com

A while back, I had a requirement to persist a record of which email addresses were sent an email through...

makandra dev
thoughtbot.com

Squirrel is an enhancement for ActiveRecord’s find method that allows programmers to query the database using a more Rubyish...

code.google.com

Web 2.0 sites have lots of tiny javascript/css files, which causes one extra round trip per file to the server...