I have a view partial that is used to render a small block of HTML content. Because of where it''s going to be placed in the HTML, it''s important that it not begin or end with any HTML whitespace. But making a sample view partial that contains nothing but a simple string, just to test things out -- when rendered it seems to still end with a newline, which is of course HTML whitespace. Even though there''s no newline in the html.erb file. Is there any simple way to make a partial view render with no newline at the end -- or the more general question, what I''m really after, with no HTML whitespace at the start or end of the partial view content? Thanks for any advice. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 7, 9:43 am, Jonathan Rochkind <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a view partial that is used to render a small block of HTML > content. Because of where it''s going to be placed in the HTML, it''s > important that it not begin or end with any HTML whitespace. > > But making a sample view partial that contains nothing but a simple > string, just to test things out -- when rendered it seems to still end > with a newline, which is of course HTML whitespace. Even though there''s > no newline in the html.erb file. > > Is there any simple way to make a partial view render with no newline at > the end -- or the more general question, what I''m really after, with no > HTML whitespace at the start or end of the partial view content?My (wild) guess is that it''s actually your ERB tag that''s adding the newline. You can use a minus sign as part of the closing ERB tag to indicate that you don''t want the newline: <%= render :partial => ''blah'' -%> Maybe this will help? Jeff purpleworkshops.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Jeff Cohen wrote:> My (wild) guess is that it''s actually your ERB tag that''s adding the > newline. > > You can use a minus sign as part of the closing ERB tag to indicate > that you don''t want the newline: > > <%= render :partial => ''blah'' -%>Aha, good point! I think you''re right. In general, for very white-space-dependent ERB partials, I''m finding it tricky to get the white space right. Are there any special tricks people have in general for controlling whitespace while still leaving readable views, other than <%- and -%>. I know about those. But even with those, I''m finding I have to jam html tags together in order to get the whitespace I want. Hmm, I just thought of one. Instead of an actual literal: <div> content </div> in the html, which leaves no good way to control output whitespace without also making the HTML kind of hard to read, I could use: <%- tag("div") do -%> <%- "content" -%> <%- end -%> Which lets me exercize complete control of whitespace supression without actually having to eliminate it in my source. Does that make any sense, or is it completely ridiculous? It''s still kind of hard to read, but in deeply nested html, still not as hard to read as "<div>lots of stuff<div>more stuff<span>more stuff</span>stuff</div></div>" all jammed together without whitespace, because I don''t want any whitespace in the output. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Apr 7, 2010 at 12:09 PM, Jeff <cohen.jeff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> My (wild) guess is that it''s actually your ERB tag that''s adding the > newline. > > You can use a minus sign as part of the closing ERB tag to indicate > that you don''t want the newline: > > <%= render :partial => ''blah'' -%> >Where is this kind of erb tags behavior documented? I was looking for it the other day and I failed at Google. -- http://twitter.com/damog http://stereonaut.net/ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > Where is this kind of erb tags behavior documented? I was looking for it > the other day and I failed at Google. >Google for erb whitespace and (from here) it''s documented on the third link: http://en.wikibooks.org/wiki/Ruby_on_Rails/ActionView/ERb I don''t know of it being in the RDocs for ERb anywhere. Cheers, Andy -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.