To find the last id of MyModel you could do

MyModel.last.id

even souds like it should )

But it's not what you really want for upper bound. In your case

MyModel.count(:all) or just MyModel.count

will fit better







On Mon, Apr 19, 2010 at 10:39 PM, Robert Walker <[email protected]>wrote:

> Eric B. wrote:
> > Franz Strebel wrote:
> >
> >> last_id = MyModel.find(:first, :order => 'id desc').id
> >
> > @Franz
> >
> > Thanks this worked great well kinda, I'm confused on why there is the
> > '.id' at the end also how would I limit this to give me say the first 3
> > from the back of the list instead of
>
> It seems obvious to me. Look at the variable used "last_id." Sending the
> "id" message to an instance of an ActiveRecord object returns the "id"
> value of the object.
>
> > :all or :first and :limit => 3
>
> my_models = MyModel.find(:all, :order => 'id desc', :limit => 3)
>
> >  didn't work because i am calling this in my 'MyModel.rb' file so in my
> > index.html.erb file its set for .each with a do loop and every other
> > thing i have tried has bombed
>
> I don't quite follow you here without seeing your code.
>
> > People may say RoR is fun and easy and at the beginning it is but
> > sometimes its really frustrating
>
> Programming is HARD! If anyone tries to tell you different then they are
> either lying to you, or are just plain gifted in the art of writing
> code. For most of us, however, it takes effort to learn.
>
> When people say RoR is fun and easy, they mean in comparison to other
> languages and frameworks.
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to