is latest a method ?

20 views
Skip to first unread message

PC Leung

unread,
Nov 12, 2013, 10:33:01 AM11/12/13
to hk...@googlegroups.com
according to the book 'Agile web dev.." page 125
I am using rails 4.0 and hit the following error.
Is latest a method or not?
Thanks


undefined method `latest' for #<Class:0x007fca86206d88>

Extracted source (around line #7):

4
5
6
7
8
9
10
          
<h1>Your Pragmatic Catalog</h1>
<% cache ['store', Product.latest] do %>
<% @products.each do |product| %>
<% cache ['entry', product] do %>
<div class="entry">

Matthew Rudy Jacobs

unread,
Nov 12, 2013, 10:41:28 AM11/12/13
to hk...@googlegroups.com
I don't have a copy of the book,
but you should probably just say `Product.last`.

The idea is to cache the products so that it gets expired when products change.

So actually Product.lastest could be defined

def Product.latest
  Product.order("updated_at DESC").first
end


--
You received this message because you are subscribed to the Google Groups "Hong Kong Ruby on Rails" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hkror+un...@googlegroups.com.
To post to this group, send email to hk...@googlegroups.com.
Visit this group at http://groups.google.com/group/hkror.
For more options, visit https://groups.google.com/groups/opt_out.

Dustin

unread,
Nov 12, 2013, 10:43:48 AM11/12/13
to hk...@googlegroups.com
You know what Russian doll caching is, but Model.latest trips you up. Search either resource:


And



Steve Holmes

unread,
Nov 12, 2013, 7:52:07 PM11/12/13
to HKROR - Hong Kong Ruby on Rails
Yup

PC, look at page 118 in the PDF (or printed page 104)

That method should be defined in your product model.

Graham Milosevic

unread,
Nov 12, 2013, 9:16:43 PM11/12/13
to hk...@googlegroups.com
I'm not sure what's on page 104, but it could be a scope instead of a method which is what I would have done.
Graham Milosevic
Phone: 6770-8171

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

PC Leung

unread,
Nov 13, 2013, 4:20:20 AM11/13/13
to hk...@googlegroups.com
thanks everybody. I find it.

config.action_controller.perform_caching = true

def self.latest 

  Product.order(:updated_at).last

end 

Reply all
Reply to author
Forward
0 new messages