Wednesday, December 8, 2010

Single table inheritance

Active Record allows inheritance by storing the name of the class in a column that by default is named “type” (can be changed by overwriting Base.inheritance_column). This means that an inheritance looking like this:

class Company < ActiveRecord::Base; end
class Firm < Company; end
class Client < Company; end
class PriorityClient < Client; end

When you do Firm.create(:name => "37signals"), this record will be saved in the companies table with type = “Firm”. You can then fetch this row again using Company.where(:name => '37signals').first and it will return a Firm object.

If you don’t have a type column defined in your table, single-table inheritance won’t be triggered. In that case, it’ll work just like normal subclasses with no special magic for differentiating between them or reloading the right type with find.

Thursday, September 9, 2010

RoR FAQ's

RUBY

1. Why RUBY?

2. Different type of variables in RUBY?

3. What is 'class' and 'module'

4. class methods vs instance methods

5. Singleton instance methods?

6. What is send method in RUBY?

7. How constructor can be create in RUBY?

8. What is inheritance how ruby supports inheritance?

9. include vs extend?

10. HOw can we call super class method from sub class?

11. what is super and how it will work?

12. proc vs block?

13. Can we extend more than one class from a Ruby class?

14. In Ruby how
method_missing
and
undefined method
can handled?

15. What is eval mention types of evals?

16. How Garbage collection handled in Ruby?

17. Ruby Symbol vs String?

18. In ruby how methods can be dynamically defined?

19. What is lambda?

20. What is meta programming?



Rails

21. Why RoR?

22. How is Rails DRY?

23. What are migrations?

24. what are associations, types of association?

25. How can we manually set the table name in model?

26. How can we manually set the primary_key in model?

27. How polymorphic association work in ROR?

28. In HABTM how can set the join table manually?

29. ActiveRecord's find vs find_by_xxxx

30. nil.id returns?

31. update_attribute vs update_attributes?

32. what is attr_accessor?



Some of the solution can find from my blog and puneeth's blog.

http://puneetitengineer.wordpress.com/2008/10/03/ruby-on-rails-interview-questions/#comment-306.

Feel free to add some more questions!!

Sunday, September 5, 2010

load vs require

Load

To load a file we use the load method:

load ‘blah.rb’

Note that we must supply the extension when we use it. When Ruby encounters a load, it will read in the contents of the file you’re trying to load. It will do this every time. No matter how many times you load the same feature, Ruby will read the file in every time it encounters a load. You’re not limited to just supplying a name and extension though, you can navigate directories e.g.:

load ‘../../blah.rb’

or even give an absolute path:

load ‘/a/b/c/blah.rb’


Require

No matter how many times you require the same feature in your program, only the first time is significant. Ruby will not re-read a file a second time, this is the first fundamental difference from how load works. The other obvious difference is the fact that you don’t need to supply an extension when you require a feature:

require ‘blah’

Friday, August 27, 2010

Ruby: Dynamically Define Method

http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html

Thursday, July 29, 2010

Wednesday, July 21, 2010

Search BY first name or last name or canacatination of first name and last name

named_scope :username_like, lambda { |value| {:conditions => ["first_name LIKE ? OR last_name LIKE ? OR CONCAT(first_name,' ',last_name) LIKE ?",value,value,value]} }

Friday, June 25, 2010