I''m trying to truncate the output of an array to a certain number. Kind of like pagination limits: :per_page =>5 Can pagination for an array be done at the view level, without having to declare it at the controller? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mon, Nov 13, 2006 at 06:49:33PM +0100, Jorge Nolla wrote:> > I''m trying to truncate the output of an array to a certain number. > > Kind of like pagination limits: > :per_page =>5 > > Can pagination for an array be done at the view level, without having to > declare it at the controller?Sure. Do something like this: irb(main):002:0> a = %w{ one two three four five size seven } => ["one", "two", "three", "four", "five", "size", "seven"] irb(main):003:0> a[0..4] => ["one", "two", "three", "four", "five"] -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry I''m kind of a newbie, I don''t know how exactly to implement that. Here is the array: <% for @post in @customer.post %> <% end %> could you show me how exactly do I have implement it. Thank you much -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mon, Nov 13, 2006 at 07:17:18PM +0100, Jorge Nolla wrote:> > Sorry I''m kind of a newbie, I don''t know how exactly to implement that. > Here is the array:I believe that you can simply insert the selection in this line: <% for @post in @customer.post %> So that it becomes: <% for @post in @customer.post[0..4] %> If that doesn''t work you could try this instead: <% @customer.post[0..4].each { |post| %> ... <% } %> -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Jacob; but both are giving me rerror messages. Don''t know what''s going on. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jacob Atzen wrote:> On Mon, Nov 13, 2006 at 07:17:18PM +0100, Jorge Nolla wrote: > > I believe that you can simply insert the selection in this line: > > <% for @post in @customer.post %> > > So that it becomes: > > <% for @post in @customer.post[0..4] %> >Does the customer model have a has_many :posts declaration in the class? If so, then it should be: <% for @post in @customer.posts %> right? It looks like @customer.post is only a single post object and in that case, it wouldn''t respond to []. I''m guessing that may be the problem based upon what you want to do and the code here... -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maybe: <ol> <% for post in @customer.posts.collection[0..4] do %> <li><%= post.title %></li> <% end %> </ol> --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
the customer model have a has_many :posts declaration in the class. here is the working model of the site www.jnolla.com:3000/content/ I''m trying to only show 4 entries on the front page, per customer. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jorge Nolla wrote:> Thanks Jacob; but both are giving me rerror messages. Don''t know what''s > going on.We can help you a lot better if you tell us what the error message is. The errors themselves have quite a bit of meaning, it''s best to read them carefully and understand them. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
use @array = @customer.post[0...4] in the controller and then <% for @item in @array -%> try to avoid any type of assignment in the view view variables should be treated as read only if you need access to the other stuff later put it in a different variable or an array of arrays -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Keynan Pratt wrote:> use > > @array = @customer.post[0...4] > > in the controller and then > > <% for @item in @array -%> > > > try to avoid any type of assignment in the view > view variables should be treated as read only > if you need access to the other stuff later put it in > a different variable or an array of arraysI''ve tried the above and it retuns this error: You have a nil object when you didn''t expect it! The error occured while evaluating nil.post -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jorge Nolla wrote:> Keynan Pratt wrote: >> use >> >> @array = @customer.post[0...4] >> >> in the controller and then >> >> <% for @item in @array -%> >> >> >> try to avoid any type of assignment in the view >> view variables should be treated as read only >> if you need access to the other stuff later put it in >> a different variable or an array of arrays > > > I''ve tried the above and it retuns this error: > > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.postThis is missing the parameter id for customer this is why it is returning nill. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry I guess this didn''t work: @customer.post[0..4] But this did: @customer.post[0...4] It was missing one period. Thank you all for your help. It works! -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---