On Nov 25, 2008, at 2:40 PM, Theo Graham-brown wrote:

>
> Hi,
>
> I'm running the following code in my show() method:
>
>        @articles = Article.find(:all, :conditions => ["issue_id = ?",
> @issue.id], :order => '`column`,position')
>
>        if (params[:article_id])
>          @article_id = params[:article_id].to_i
>          c = 0
>          total = @articles.count
....
>        end
>
> Now to be honest this code is already a bit odd for me but I have no
> idea how else to approach this in Ruby on Rails. So I've attempted  
> to do
> it PHP-style. But I'm being told that I can't do @articles.count
>
> Why? I have a user model and a user has a one to many relationship  
> with
> articles so I know that: @user.articles.count works. Hence I'm  
> guessing
> there's something big I'm missing here.
>
> So, how am I going to do this? How do I easily cycle through my list  
> of
> articles and get the previous and next ones?

@user.articles.count is Rails magic.  It's not actually fetching  
everything and then counting it up, it's looking at the associations  
and building a "SELECT COUNT...."

@articles above is an array.  Try @articles.size.

-philip

--~--~---------~--~----~------------~-------~--~----~
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