Using rails 2.3.2 I have a partial _foo.rhtml that begins with a comment as follows: <% # here is a comment %> <li><%= foo %></li> When I render the partial from a view in the traditional way, e.g. <% some_numbers = [1, 2, 3, 4, 5] %> <ul> <%= render :partial => "foo", :collection => some_numbers %> </ul> I found that the <li> and </li> tags are not rendered. However, I can solve this problem by fixing _foo.rhtml to eliminate the space between <% and # so that it reads: <%# here is a comment %> <li><%= foo %></li> My question: what''s going on here? E.g., is <% # comment %> simply incorrect syntax for including comments in a template? Or is the problem more subtle? Thanks! -- 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.
2010/1/18 Benjamin Rahn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Using rails 2.3.2 I have a partial _foo.rhtml that begins with a comment > as follows: > > <% # here is a comment %> > <li><%= foo %></li> > > When I render the partial from a view in the traditional way, e.g. > > <% some_numbers = [1, 2, 3, 4, 5] %> > <ul> > <%= render :partial => "foo", :collection => some_numbers %> > </ul> > > I found that the <li> and </li> tags are not rendered. However, I can > solve this problem by fixing _foo.rhtml to eliminate the space between > <% and # so that it reads: > > <%# here is a comment %> > <li><%= foo %></li> > > My question: what''s going on here? E.g., is <% # comment %> simply > incorrect syntax for including comments in a template? Or is the > problem more subtle?<% # is invalid syntax, the only comment syntax allowed in erb is <%# Unfortunately using <% # does not necessarily give a syntax error, just unexpected results. Colin> > Thanks! > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > > > >-- 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.
The result is pretty much expected. Since you started the general Ruby code block, the closing "%>" is now the part of the comment and doesn''t denote the code block end any more. To see the difference, try: <% # Comment %> - Aleksey On Jan 18, 7:47 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2010/1/18 Benjamin Rahn <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: > > > > > > > Using rails 2.3.2 I have a partial _foo.rhtml that begins with a comment > > as follows: > > > <% # here is a comment %> > > <li><%= foo %></li> > > > When I render the partial from a view in the traditional way, e.g. > > > <% some_numbers = [1, 2, 3, 4, 5] %> > > <ul> > > <%= render :partial => "foo", :collection => some_numbers %> > > </ul> > > > I found that the <li> and </li> tags are not rendered. However, I can > > solve this problem by fixing _foo.rhtml to eliminate the space between > > <% and # so that it reads: > > > <%# here is a comment %> > > <li><%= foo %></li> > > > My question: what''s going on here? E.g., is <% # comment %> simply > > incorrect syntax for including comments in a template? Or is the > > problem more subtle? > > <% # is invalid syntax, the only comment syntax allowed in erb is <%# > > Unfortunately using <% # does not necessarily give a syntax error, > just unexpected results. > > Colin > > > > > > > Thanks! > > -- > > Posted viahttp://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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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.
Colin Law wrote:> ... > <% # is invalid syntax, the only comment syntax allowed in erb is <%#It is not actually invalid. Just the rest of the line is considered as comment including %>. Working (though ugly) code was: <% # here is a comment %> T. -- 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.
2010/1/18 T.N. T. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Colin Law wrote: >> ... >> <% # is invalid syntax, the only comment syntax allowed in erb is <%# > > It is not actually invalid. Just the rest of the line is considered as > comment including %>. Working (though ugly) code was: > > <% # here is a comment > %>It may work but I am not sure it is valid erb syntax. In a previous version of Rails <% # comment %> worked. I am not sure that <% # here is a comment %> can be guaranteed to work in the future. I may be wrong though. Colin -- 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.
Colin Law wrote:> It may work but I am not sure it is valid erb syntax. In a previous > version of Rails <% # comment %> worked. I am not sure that > <% # here is a comment > %> > can be guaranteed to work in the future. I may be wrong though.Your probably right. And there really should be at least a warning when it is found in a template. -- 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.
Marnen Laibow-Koser
2010-Jan-18 14:52 UTC
Re: Re: Comment syntax and strange partial rendering
T. N. T. wrote:> Colin Law wrote: >> It may work but I am not sure it is valid erb syntax. In a previous >> version of Rails <% # comment %> worked. I am not sure that >> <% # here is a comment >> %> >> can be guaranteed to work in the future. I may be wrong though. > > Your probably right. And there really should be at least a warning when > it is found in a template.Wow! Add this weirdness to the list of reasons to use Haml rather than ERb (as if I needed more reasons... :) ). Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. --0015174760d8b062f4047d7181b0 Content-Type: text/plain; charset=ISO-8859-1 -- 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. --0015174760d8b062f4047d7181b0--
2010/1/18 Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:>... > > Wow! Add this weirdness to the list of reasons to use Haml rather than > ERb (as if I needed more reasons... :) ).I am with you on that one Marnen. I tried haml a little while ago and was immediately hooked. I would highly recommend anyone who has not tried it to have a go. Colin -- 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.
Ah, this makes a lot of sense...thanks everyone! -Ben PS If content-free thank-yous isn''t appropriate ettiquette, please let me know :) -- 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.