rails

A collection of 9 posts

Jul 15, 2019

How to (not) use unscoped in Rails

Active Record provides unscoped to remove all the scopes added to a model previously.class Article default_scope { where(published: true) } end Article.all # SELECT * FROM articles WHERE published = true Article.unscoped # SELECT

Feb 23, 2014

Devise : Passing params to after_* paths

Devise allows us to customize after_signup_path by overriding a protectedmethod in RegistrationsController.class RegistrationsController < Devise::RegistrationsController protected def after_inactive_sign_up_path_for(resource) your_custom_path end def

Jan 19, 2014

VERP on Rails

We sent newsletter campaigns from our Rails app. One of the main requirement of such campaign is how many emails bounced?. We need to track all bounced emails and map them again to

Oct 26, 2013

Preload associations with `find_by_sql`

I have a very complex query which is made up of more than 1 subqueries. Arel is awesome, but it can’t generate that query. So i generate those subqueries separately and combine

Oct 14, 2013

Conditional where in rails

T.L.D.RYou can pass blank object to where clause and it will return current relation as it is.Long versionSometimes, we need to apply where clause conditionally. For eg. apply timeframe