I''m customizing my scaffold on a simple app by adding a little formatting. However, the <hr> that I put inside the table row that displays the row gets moved outside the table and I can''t figure out why. Here''s the scaffold code with the <hr> marked: =================<table> <tr> <th>Description</th> <th>Date Entered</th> <th>Source</th> <th>Tags</th> </tr> <% counter = 0 %> <% for idea in @ideas %> <% counter = counter + 1 %> <%= "<tr id=\"row-#{counter}\"><hr>" %> <================== <td><%= idea.send("description")[0,145]%> <% if idea.description.length > 145 %> ... <% end %> </td> <td><%= idea.send("date_entered") %></td> <td><%= idea.send("source") %></td> <td><%= idea.tag_names.join('', '') %></td> <td><%= link_to ''Show'', :action => ''show'', :id => idea %></td> <td><%= link_to ''Edit'', :action => ''edit'', :id => idea %></td> <td><%= link_to ''Destroy'', { :action => ''destroy'', :id => idea }, :confirm => ''Are you sure?'', :method => :post %></td> </tr> <% end %> </table> =======================And here''s the result - notice that all the <hr> elements have been moved completely outside the table??? =======================<h1> Listing ideas </h1> <hr> <=====================<hr> <hr> <hr> <hr> <hr> <hr> <hr> <hr> <hr> <table> <tbody> <tr> <th> Description </th> <th> Date Entered </th> <th> Source </th> <th> Tags </th> </tr> <tr id="row-1"> <td> ======================= It''s gotta be something simple I''m overlooking, but I can''t seem to find the problem. thanks...jon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Jon, JSeidel wrote:> I''m customizing my scaffold on a simple app by adding a little > formatting. However, the <hr> that I put inside the table row that > displays the row gets moved outside the table and I can''t figure out > why. > > Here''s the scaffold code with the <hr> marked:<snip>> <%= "<tr id=\"row-#{counter}\"><hr>" %>I think Rails is having a problem matching your quotes. You''re wanting nested, and it''s seeing a series. It looks like you''ve tried to escape the quotes but I don''t think that''ll work here. Try... <%= %Q{<tr id="row-#{counter}"><hr>} %> hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Actually, Bill, I have exactly the same problem when I simplify the code to: ==<tr><hr> == ...jon On Jul 1, 9:51 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> Hi Jon, > > > > JSeidel wrote: > > I''m customizing my scaffold on a simple app by adding a little > > formatting. However, the <hr> that I put inside the table row that > > displays the row gets moved outside the table and I can''t figure out > > why. > > > Here''s the scaffold code with the <hr> marked: > <snip> > > <%= "<tr id=\"row-#{counter}\"><hr>" %> > > I think Rails is having a problem matching your quotes. You''re wanting > nested, and it''s seeing a series. It looks like you''ve tried to escape the > quotes but I don''t think that''ll work here. Try... > <%= %Q{<tr id="row-#{counter}"><hr>} %> > > hth, > Bill--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
My bad! I had to specify this: ==== <tr><td colspan="7"><hr></td></tr> ====to get the <hr> to cover the entire table. ...jon On Jul 1, 9:18 am, JSeidel <jsei...-SqBBwp4wwK4AvxtiuMwx3w@public.gmane.org> wrote:> I''m customizing my scaffold on a simple app by adding a little > formatting. However, the <hr> that I put inside the table row that > displays the row gets moved outside the table and I can''t figure out > why. > > Here''s the scaffold code with the <hr> marked: > =================> <table> > <tr> > <th>Description</th> > <th>Date Entered</th> > <th>Source</th> > <th>Tags</th> > </tr> > <% counter = 0 %> > <% for idea in @ideas %> > <% counter = counter + 1 %> > <%= "<tr id=\"row-#{counter}\"><hr>" %> <==================> <td><%= idea.send("description")[0,145]%> > <% if idea.description.length > 145 %> > ... > <% end %> > </td> > <td><%= idea.send("date_entered") %></td> > <td><%= idea.send("source") %></td> > <td><%= idea.tag_names.join('', '') %></td> > <td><%= link_to ''Show'', :action => ''show'', :id => idea %></td> > <td><%= link_to ''Edit'', :action => ''edit'', :id => idea %></td> > <td><%= link_to ''Destroy'', { :action => ''destroy'', :id => > idea }, :confirm => ''Are you sure?'', :method => :post %></td> > </tr> > <% end %> > </table> > =======================> And here''s the result - notice that all the <hr> elements have been > moved completely outside the table??? > =======================> <h1> > Listing ideas > </h1> > <hr> <=====================> <hr> > <hr> > <hr> > <hr> > <hr> > <hr> > <hr> > <hr> > <hr> > <table> > <tbody> > <tr> > <th> > Description > </th> > <th> > Date Entered > </th> > <th> > Source > </th> > <th> > Tags > </th> > </tr> > <tr id="row-1"> > <td> > =======================> > It''s gotta be something simple I''m overlooking, but I can''t seem to > find the problem. > > thanks...jon--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Glaesemann
2007-Jul-01 19:10 UTC
Re: Problem with <hr> placement in scaffold code...
On Jul 1, 2007, at 12:23 , JSeidel wrote:> > My bad! I had to specify this: > ====> <tr><td colspan="7"><hr></td></tr> > ====> to get the <hr> to cover the entire table.Note that if you''re using XHTML, <hr> is invalid. Use <hr /> instead. I''m curious why you''re using <hr> here rather than just using CSS to style your <table>, <tr>, and <td> elements? <hr> is pretty much just a style element (i.e., it doesn''t convey meaning), and it''s generally better to separate your content (the HTML) from presentation (the CSS). Here are some other hints you might consider:> On Jul 1, 9:18 am, JSeidel <jsei...-SqBBwp4wwK4AvxtiuMwx3w@public.gmane.org> wrote: > >> <% counter = counter + 1 %><% counter += 1 %> (And if you''re immediately incrementing your counter, you might as well initialize it to what you want and increment at the bottom of the loop rather than the top.)>> <%= "<tr id=\"row-#{counter}\"><hr>" %> >> <==================As a matter of style, I find it much harder to read tags which are quoted. The idea of using an erb template is that you can use your tags as tags rather than building up and printing strings, e.g., <tr id="row-<%= counter %>">>> <td><%= idea.send("description")[0,145]%> >> <% if idea.description.length > 145 %> >> ... >> <% end %> >> </td>You can use the truncate() helper to handle shortening idea.description rather than handling it yourself: <td><%= h truncate(idea.description, 145) %></td> It''s also a good idea to use the h() helper to html-escape your strings.>> <td><%= idea.send("date_entered") %></td> >> <td><%= idea.send("source") %></td>I''m not quite sure why you''re using #send here rather than just <td><%= h idea.date_entered %></td> <td><%= h idea.source %></td> Note, I''ve again used the h() helper method. Putting these all together, you get (untested): <table> <tr> <th>Description</th> <th>Date Entered</th> <th>Source</th> <th>Tags</th> <th colspan="3"></th> </tr> <% counter = 1 %> <% for idea in @ideas %> <tr id="row-<%= counter %>"> <td><%= h truncate(idea.description, 145) %></td> <td><%= h idea.date_entered %></td> <td><%= h idea.source %></td> <td><%= h idea.tag_names.join('', '') %></td> <td><%= link_to ''Show'', :action => ''show'', :id => idea %></td> <td><%= link_to ''Edit'', :action => ''edit'', :id => idea %></td> <td><%= link_to ''Destroy'', { :action => ''destroy'', :id => idea }, :confirm => ''Are you sure?'', :method => :post %></td> </tr> <% counter += 1 %> <% end %> </table> Personally, I think that''s a little easier to read, and perhaps more idiomatic. Hope this helps. Michael Glaesemann grzm seespotcode 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-/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 -~----------~----~----~----~------~----~------~--~---
Michael... Thank you very much; excellent comments - I will definitely incorporate them. Regarding use of <hr /> versus CSS - I''m building this up by stages and adding the hr is much easier (ignoring my errors) than id''ing the elements and CSS''ing them, IMO. Were I to upgrade the display more fully, then I would definitely go CSS (which I do use for much of my styling). Minor point: coming from Perl, I was looking for the counter++ syntax and, failing to find that, went completely the other way forgetting the (op)= in my flustered state :-) Cheers; and thanks again. ...jon -- -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Michael Glaesemann Sent: Sunday, July 01, 2007 12:10 PM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: Problem with <hr> placement in scaffold code... On Jul 1, 2007, at 12:23 , JSeidel wrote:> > My bad! I had to specify this: > ====> <tr><td colspan="7"><hr></td></tr> > ====> to get the <hr> to cover the entire table.Note that if you''re using XHTML, <hr> is invalid. Use <hr /> instead. I''m curious why you''re using <hr> here rather than just using CSS to style your <table>, <tr>, and <td> elements? <hr> is pretty much just a style element (i.e., it doesn''t convey meaning), and it''s generally better to separate your content (the HTML) from presentation (the CSS). Here are some other hints you might consider:> On Jul 1, 9:18 am, JSeidel <jsei...-SqBBwp4wwK4AvxtiuMwx3w@public.gmane.org> wrote: > >> <% counter = counter + 1 %><% counter += 1 %> (And if you''re immediately incrementing your counter, you might as well initialize it to what you want and increment at the bottom of the loop rather than the top.)>> <%= "<tr id=\"row-#{counter}\"><hr>" %> >> <==================As a matter of style, I find it much harder to read tags which are quoted. The idea of using an erb template is that you can use your tags as tags rather than building up and printing strings, e.g., <tr id="row-<%= counter %>">>> <td><%= idea.send("description")[0,145]%> >> <% if idea.description.length > 145 %> >> ... >> <% end %> >> </td>You can use the truncate() helper to handle shortening idea.description rather than handling it yourself: <td><%= h truncate(idea.description, 145) %></td> It''s also a good idea to use the h() helper to html-escape your strings.>> <td><%= idea.send("date_entered") %></td> >> <td><%= idea.send("source") %></td>I''m not quite sure why you''re using #send here rather than just <td><%= h idea.date_entered %></td> <td><%= h idea.source %></td> Note, I''ve again used the h() helper method. Putting these all together, you get (untested): <table> <tr> <th>Description</th> <th>Date Entered</th> <th>Source</th> <th>Tags</th> <th colspan="3"></th> </tr> <% counter = 1 %> <% for idea in @ideas %> <tr id="row-<%= counter %>"> <td><%= h truncate(idea.description, 145) %></td> <td><%= h idea.date_entered %></td> <td><%= h idea.source %></td> <td><%= h idea.tag_names.join('', '') %></td> <td><%= link_to ''Show'', :action => ''show'', :id => idea %></td> <td><%= link_to ''Edit'', :action => ''edit'', :id => idea %></td> <td><%= link_to ''Destroy'', { :action => ''destroy'', :id => idea }, :confirm => ''Are you sure?'', :method => :post %></td> </tr> <% counter += 1 %> <% end %> </table> Personally, I think that''s a little easier to read, and perhaps more idiomatic. Hope this helps. Michael Glaesemann grzm seespotcode 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-/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 -~----------~----~----~----~------~----~------~--~---
Michael Glaesemann
2007-Jul-01 23:50 UTC
Re: Problem with <hr> placement in scaffold code...
On Jul 1, 2007, at 16:40 , Jon Seidel CMC wrote:> Michael... Thank you very much; excellent comments - I will definitely > incorporate them.I''m glad you found them helpful. I always wonder whether or not to comment on issues I see in code other than what the poster is directly asking about.> Minor point: coming from Perl, I was looking for the counter++ > syntax and, > failing to find that, went completely the other way forgetting the > (op)= in > my flustered state :-)I hear you :) My language route has been PHP to Perl to Ruby and I''m currently studying C :) While there are usually many different ways to accomplish a given task, learning the idioms of a particular language is interesting. Michael Glaesemann grzm seespotcode 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-/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 -~----------~----~----~----~------~----~------~--~---