views:

17

answers:

1

Hi, i'm new to rails.

i'm trying to get some results from table in a controller using the limit method.

I did that on the controller:

@articles = Article.limit(5) 

And i got NoMethodError exception : undefined method `limit'

But when i did it that way it worked:

@articles = Article.all(:limit => 5)

Although i saw the first method on ror guides, why it didn't work for me?

+2  A: 

Are you using rails 3? The limit method is only available in in Rails versions >= 3.0.

thargor
@tzvika: The [Rails 3 release notes](http://guides.rubyonrails.org/3_0_release_notes.html) mention these [new query methods](http://guides.rubyonrails.org/3_0_release_notes.html#query-interface), and links to a blog entry that [describes them in more detail](http://m.onkey.org/2010/1/22/active-record-query-interface).
Chris Johnsen
thanks, it is rails 2.3.8 , that's the reason.
tzvika ofek