Hello, When printing the data from a database table to an html table in index.html.erb, there is a strange output in which the entire table is printed sequentially and unformatted, followed by the actual formatted data. The formatted data is correct, along with its headers and some links. After the html headers are printed in a table row: <table> <tr> <th>First name</th> ... then the table data is printed: <%= @people.each do |person| %> <tr> <td><%= person.first_name %></td> <td><%= person.middle_name %></td> ... and by the process of elimination, the offending line is <%@people.each do |person| %> as the table data dump occurs even when it is alone (except for the following <% end %>). But, of course, I can''t do without it or I wouldn''t get all of the table data. How do I fix that line, or what is the replacement which still iterates through the table? Thanks, Barney -- 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 Jul 25, 2011, at 7:03 PM, Barney wrote:> Hello, > When printing the data from a database table to an html table in > index.html.erb, there is a strange output in which the entire table is > printed sequentially and unformatted, followed by the actual formatted > data. The formatted data is correct, along with its headers and some > links. > After the html headers are printed in a table row: > > <table> > <tr> > <th>First name</th> > ... > then the table data is printed: > > <%= @people.each do |person| %> > <tr> > <td><%= person.first_name %></td> > <td><%= person.middle_name %></td> > ... > and by the process of elimination, the offending line is <%> @people.each do |person| %> as the table data dump occurs even when itThat should be <% @people.each do |person| %> Or even better, <%- @people.each do |person| -%> which will not add an empty line to your output HTML. Walter> is alone (except for the following <% end %>). But, of course, I can''t > do without it or I wouldn''t get all of the table data. > How do I fix that line, or what is the replacement which still > iterates through the table? > Thanks, > Barney > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > 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.
Thanks Walter! That did the trick! Do you have a link where I can read about the differences between < %= ... , <%-... and <% ? I haven''t spotted that in the "Agile Web Development with Rails" book I''m reading. Barney On Jul 25, 7:25 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On Jul 25, 2011, at 7:03 PM, Barney wrote: > > > > > Hello, > > When printing the data from a database table to an html table in > > index.html.erb, there is a strange output in which the entire table is > > printed sequentially and unformatted, followed by the actual formatted > > data. The formatted data is correct, along with its headers and some > > links. > > After the html headers are printed in a table row: > > > <table> > > <tr> > > <th>First name</th> > > ... > > then the table data is printed: > > > <%= @people.each do |person| %> > > <tr> > > <td><%= person.first_name %></td> > > <td><%= person.middle_name %></td> > > ... > > and by the process of elimination, the offending line is <%> > @people.each do |person| %> as the table data dump occurs even when it > > That should be <% @people.each do |person| %> > > Or even better, <%- @people.each do |person| -%> which will not add an > empty line to your output HTML. > > Walter > > > is alone (except for the following <% end %>). But, of course, I can''t > > do without it or I wouldn''t get all of the table data. > > How do I fix that line, or what is the replacement which still > > iterates through the table? > > Thanks, > > Barney > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Jul 25, 2011 at 5:24 PM, Barney <bsperlin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Do you have a link where I can read about the differences between < > %= ... , <%-... and <% ? I haven''t spotted that in the "Agile Web > Development with Rails" book I''m reading.Look in the index for "ERb" -- my old second edition covers this on page 40-43. HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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.
It''s pretty basic: <%= foo %> means print whatever is inside to the output. In Rails 2.3, it means literally print it whatever it is. In Rails 3 and up, it means html-escape it and print it. <% foo %> means this is an instruction line, a bit of Ruby mixed in among the HTML. You use this to start and end your loops over a collection, or put an island of logic or data in the view. If you put a puts command in there, then it''s functionally the same thing as the first one, but if you don''t explicitly print anything, it''s just a program step. <%- foo -%> means this is an instruction line, but in addition, don''t leave an extra line of whitespace where it was, just do the Ruby instruction and don''t add any whitespace. Walter On Jul 25, 2011, at 8:30 PM, Hassan Schroeder wrote:> On Mon, Jul 25, 2011 at 5:24 PM, Barney <bsperlin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Do you have a link where I can read about the differences between < >> %= ... , <%-... and <% ? I haven''t spotted that in the "Agile Web >> Development with Rails" book I''m reading. > > Look in the index for "ERb" -- my old second edition covers this on > page 40-43. > > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://about.me/hassanschroeder > twitter: @hassan > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > 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.
Ah, yes, on p. 21 it says that <%= will execute the Ruby, HTML-escape it, convert it to a string and print it to the screen. Unfortunately, just because I read something doesn''t mean I remember it! Thanks to Walter and Hassan for reminding me! Barney On Jul 25, 8:42 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> It''s pretty basic: > > <%= foo %> means print whatever is inside to the output. In Rails 2.3, > it means literally print it whatever it is. In Rails 3 and up, it > means html-escape it and print it. > > <% foo %> means this is an instruction line, a bit of Ruby mixed in > among the HTML. You use this to start and end your loops over a > collection, or put an island of logic or data in the view. If you put > a puts command in there, then it''s functionally the same thing as the > first one, but if you don''t explicitly print anything, it''s just a > program step. > > <%- foo -%> means this is an instruction line, but in addition, don''t > leave an extra line of whitespace where it was, just do the Ruby > instruction and don''t add any whitespace. > > Walter > > On Jul 25, 2011, at 8:30 PM, Hassan Schroeder wrote: > > > On Mon, Jul 25, 2011 at 5:24 PM, Barney <bsper...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Do you have a link where I can read about the differences between < > >> %= ... , <%-... and <% ? I haven''t spotted that in the "Agile Web > >> Development with Rails" book I''m reading. > > > Look in the index for "ERb" -- my old second edition covers this on > > page 40-43. > > > HTH, > > -- > > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > >http://about.me/hassanschroeder > > twitter: @hassan > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.