can rails active-record's methods accept a parameter in an array format?

Go To StackoverFlow.com

1

I have a model 'Car'. Its structure looks like this.

Car
=========
Make:string
Year:integer

Before, I learned that some methods in ruby, especially active record's, actually take an array as parameter.

Then, instead of finding a collection in traditional way:

Car.find(:all, :limit => 10, :offset => 5)

Can I perform searching the collection like this?

Car.find([:all, {:limit => 10, :offset => 5}])

I have tried above in the console, but it didn't work for me. I'm just curious to know why it didn't work the way it was supposed to be.

any advice would be really appreciated.

2012-04-04 07:46
by Sarun Sermsuwan
Did the answer help you? If so, can you upvote it and accept it? Otherwise I'd prefer to delete it. Thanks - joelparkerhenderson 2012-11-29 15:31


0

You can not pass the argument like array, its predefined for ids. like:

Car.find([1,2,3,4,5])

Have a look on link : http://apidock.com/rails/ActiveRecord/Base/find/class

2012-04-04 08:03
by Vik
I don't know whats wrong here. Can you please let me know , why its down voted - Vik 2012-04-04 08:06
He's not asking about find; he's asking about limit & offse - joelparkerhenderson 2012-04-04 08:15
He's asking about using arrays as parameters to active record methods. I think limit and offset are just the examples he chose. I think this is a valid answer, although yours is obviously the correct way to solve the example given - John Plummer 2012-04-04 09:30
@Vik John Plummer makes a good point-- if you can do a quick edit to your answer, I'll be allowed to change the downvote to upvote - joelparkerhenderson 2012-12-08 16:13
Ads