views:

37

answers:

2

Hi

I want to retrieve the first two records from collection such that, collection is like:

@collect_firstnames = @name.firstnames

From this collection I want to fetch first two records...

I used limit it is not working, :limit => 2

A: 

You can use the :limit option like this:

@first_two = Name.find(:all, :limit => 2)

Edit

It's the same idea, assuming firstnames is a relationship (just like Swanand said below)

@first_two = @name.firstnames.all(:limit => 2)
j.
i want to fetch first two from the collection
nirmal
+3  A: 

I take it that @name.firstnames is a has_many relationship. You need to pass the options to all:

@name.firstnames.all(:limit => 2)
Swanand