Web Development

Rails has been making leaps and bounds in the web development industry. It introduced many neat stuffs like the asset pipeline and turbolinks‎.

ActiveRecord has of course never needed this functionality but it still neat.

We have always used something like this to query a NOT IN in query:

User.where('username != ?', params[:username])
// "SELECT "users".* FROM "users"  WHERE "users"."username" != 'teejay'"

If using arel, you can do this:

posts = Post.arel_table
Post.where(posts[:title].in(['Testing', 'Test']).not)
// "SELECT "posts".* FROM "posts" WHERE (NOT ("posts"."title" IN ('Testing', 'Test')))"

Rails 4 introduced the not method which lets us write this:

User.where.not(username: params[:username])
// "SELECT "users".* FROM "users"  WHERE "users"."username" != 'teejay'"
User.where.not(username: ['teejay', 'obazee'])
// "SELECT "users".* FROM "users"  WHERE ("users"."username" NOT IN ('teejay', 'obazee'))"

Cool huh?