Fetch data from heterogenous tables(Rails SQL views, SQL Union)

Let’s say you have a ‘cars’ table and a ‘bikes’ table, and the schema can not be changed. Some fields are the same, and you want to display ( paginate, search etc) a list with products that are both cars and bikes (from both the car and the bike models), sorted by their creation date.

This post is about how this can be accomplished using sql views.

Continue reading

Ruby on Rails Interview questions – update

Most of Google searches that hit my blog are about ‘ruby on rails interview questions‘.

Responding to this popular request đŸ˜‰ , I will post 3 more questions that are related.

1. What type of data would you use to represent currency?

2. Why is it not a good practice to use float for currency?

3. Explain the following behaviour:

~$ ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
~$ irb
irb(main):003:0> (10.12*100).to_i
=>; 1011

The answer – in my next post .

Ruby on Rails interview questions – part 2

Continuing the “RoR interview questions” sequel(part one here) , these are some general Rails concepts and technologies questions. Enjoy :).

Continue reading

SEAM: Entity Inheritance

I will make a comparison on how the SEAM (Hibernate) framework and Rails framework handles model inheritance.

This first article is about SEAM.

Continue reading

Searchlogic plugin: ActiveRecord search on Steroids

Searchlogic is everything you would ever wish from AR search and you could not find.

The brilliant ideea is that the search itself is seen as an object, so you can add/remove conditions very easy.

search = User.new_search
search.conditions.hour_of_created_at = 5

Continue reading