ruby / rails interview questions
i’ve been digging around lately for interview questions to use when interviewing a ruby and rails candidate.
there are few good resources for this:
i’m adding a few more with some solutions, designed to test the breadth of someone’s knowledge.
h3. what do you not like about ruby on rails? identify its weak points.
the answers i expect here are fixtures, routes, scalability. bonus points for identifying the weakness in using multiple databases.
a good followup on scalability is: how have you in the past dealt with the scalability problems, and what does your preferred deployment environment look like?
what is the difference between a symbol and a string? when should they be used?
a symbol has a shorter reference number, which makes it faster to look up. if you’re using something as a reference string, a symbol is a good idea. if you’re planning on a string being editable, then a string is a better idea.
good information on this here: 13 ways of looking at a ruby symbol
when would you use request.xhr?
to test for an XmlHttpRequest, if you were writing a single method to deal with each request type. bonus: this has been dusted somewhat in rails 2, wherein you deal with the response where it belongs, in the response:
1 def action
2 # .. some code
3 respond_to do |format| do
4 format.html { ... }
5 format.js { ... }
6 format.xml { ... }
7 end
8 end
when would you use has_many :through?
to create an association without creating a new table, if the information can be related through an existing table.
when would you use a polymorphic association? is there a better method?
the better method is has_many_polymorphs . generally, you want to use a polymorphic association when you want to treat a group of objects uniformly from a parent’s point of view.
when is it appropriate to use a helper method? where should that helper method live?
helper methods should generate markup. that is all. the helper method should live in the controller of a particular object if that markup is particular that object, especially if it is similar or has the same method signature across a number of objects, and each is handled differently (but share partials). generally applicable helpers should live in the helpers … [read more >>]

XML