Here is a probably an easy output formatting problem.
I am trying to output a sentence that uses commas between each item
(retailer) and a period once there are no more items.
The problem is, I can''t remove the space before my commas in the
output. I''ve tried putting the html in quotes, but for some reason the
html injects a space between my variable output and the following
text. How can I solve this?
The second problem is my variable count increments correctly, but it
does not trigger the ''else''. Any ideas why?
# the output #
...Write a review on Amazon.com , and GAP , and Limited ,
# the view #
<% for review in @reviews -%>
<% count += 1 -%>
<%= link_to review.retailer.name, retailer_path(review) -%>
<%= if count == @reviews
'', ''
else
'', and ''
end -%>
<% end %>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
>> %w(foo bar baz).to_sentence=> "foo, bar, and baz" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What a nice nugget! Could you enlighten me as to what the %w does? On Sep 12, 8:27 pm, "Xavier Noria" <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> >> %w(foo bar baz).to_sentence > > => "foo, bar, and baz"--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
How could I use a hash with ''.to_sentence''. I don''t have set variables, and I don''t know how many I''ll have. On Sep 12, 8:27 pm, "Xavier Noria" <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> >> %w(foo bar baz).to_sentence > > => "foo, bar, and baz"--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier, Thanks! You put me on the right path...
This does a beautiful job:
@reviews.collect {|r| r.retailer.name}.to_sentence
On Sep 12, 8:31 pm, yachtman
<carson.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> How could I use a hash with ''.to_sentence''. I
don''t have set
> variables, and I don''t know how many I''ll have.
>
> On Sep 12, 8:27 pm, "Xavier Noria"
<f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:
>
> > >> %w(foo bar baz).to_sentence
>
> > => "foo, bar, and baz"
>
>
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Fri, Sep 12, 2008 at 2:30 PM, yachtman <carson.cole-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > What a nice nugget! Could you enlighten me as to what the %w does?It is shorthand for [''foo'', ''bar'', ''baz'']. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
FYI, the extra spaces were from the indentation of each line of ERB. --Matt Jones --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---