Adrian's Findings & Learnings

  • Archive
  • RSS

What’s The Relation Between Rack, Rack Application, Rack Middleware, Rackup & Rails Application?

A mouth full of terms indeed! How else could I have shorten the title? Anyways, since you’re reading this, I’m sure you are confused as I am when I first came into these terms myself. Hope this post helps you understand better what all these are and how they relate to one another.

image

What is Rack?

Traditionally, ruby web framework developers would write an adapter for each web server they wanted their web framework to support. This is obviously unsustainable, hence a standard solutions is needed. Rack to the Rescue! Rack defines a standard way of interaction between web servers and ruby web applications. Rack basically is both a simple specification (the standard) and ruby library for connecting web servers to ruby web applications. 

The Specification: Defines two things: an environment (env), which is a hash that contains CGI-like headers describing the request and a response, which is an array of values including the [response code, response headers, and response body].

Ruby Library: List of all modules and classes are available at http://rack.rubyforge.org/doc/classes/Rack.html

Read More

    • #Ruby on Rails
  • 1 year ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Rails 3 + Arel: Left outer join with table aliasing (Part 2)

It wasn’t until I read an article by Ernie Miller on MetaWhere, that I found out the lies that “.to_sql” has been putting me up with. Apparently, “.to_sql” doesn’t show you everything under the hood. For example:

Task.includes(:creator).where(“users.username LIKE ‘%manager%’”).to_sql
# Outputs “SELECT `tasks`.* FROM `tasks` WHERE (users.username LIKE ‘%manager%’)”

With MetaWhere’s own “.debug_sql”, I was then able to see the complete SQL query that was being executed against my tables.

Task.includes(:creator).where(“users.username LIKE ‘%manager%’”).debug_sql
# Outputs “SELECT * FROM tasks LEFT OUTER JOIN users ON users.id = tasks.creator_id AND users.deleted_at IS NULL WHERE (users.username LIKE ‘%manager%’)”

Now that the issue with “Includes” has been straightened, lets see the updated Task example that I’ve given in Part I.

IMPORTANT: Take note of the updated alias name for the Users table. I’ve updated it to “creators_tasks” as including :creators into your query will result in a default aliasing of users table as “creators_users” in SQL

    • #Ruby on Rails
  • 1 year ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

About

Founder of Highrisepro.com, Ruby on Rails Developer, UI/UX Designer, Lean Startup Practitioner & Proud Father of Fraternal Boys - Montreal, CA

Pages

  • Portfolio

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile
Effector Theme by Pixel Union