it seems that <% %> is not exactly the same as <?php ?> in which, PHP''s <?php echo "something" ?> will add to the output but ERB''s <% puts "something" %> will not? Does someone know if JSP and ASP behave like ERB or PHP and can make a summary of their likes and differences? Thank you. -- Posted via http://www.ruby-forum.com/.
Jian Lin wrote:> it seems that <% %> is not exactly the same as <?php ?> in which, > > > PHP''s > <?php echo "something" ?> > > will add to the output > > but > > ERB''s > <% puts "something" %> > > will not?actually, i found that <% puts 123 %> prints 123 to the stdout. so the shell that is running script/server will see "123"... but the 123 is not part of the webpage generated. Is there a way or option to include that 123 as part of the generated HTML? thanks. -- Posted via http://www.ruby-forum.com/.
<%= "blah" %> is what you are looking for RobL http://www.robl.me 2009/5/9 Jian Lin <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > Jian Lin wrote: > > it seems that <% %> is not exactly the same as <?php ?> in which, > > > > > > PHP''s > > <?php echo "something" ?> > > > > will add to the output > > > > but > > > > ERB''s > > <% puts "something" %> > > > > will not? > > actually, i found that <% puts 123 %> prints 123 to the stdout. so the > shell that is running script/server will see "123"... but the 123 is not > part of the webpage generated. Is there a way or option to include that > 123 as part of the generated HTML? thanks. > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Rob Lacey contact-+WAvBcCRUVA@public.gmane.org http://www.robl.me --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rob Lacey wrote:> <%= "blah" %> > > is what you are looking foractually... sometimes i want to output multiple things inside of <% %>, or put everything inside a loop and inside a <% %>, so that''s why the question of <% puts 123 %> -- Posted via http://www.ruby-forum.com/.
Jian Lin wrote:> actually... sometimes i want to output multiple things inside of <% %>, > or put everything inside a loop and inside a <% %>, so that''s why the > question of <% puts 123 %>I think you should use something like: <% for x in y do %> <%= "#{x.z}, #{x.a}" %> <% end %> -- Posted via http://www.ruby-forum.com/.
Alberto Santini wrote:> Jian Lin wrote: >> actually... sometimes i want to output multiple things inside of <% %>, >> or put everything inside a loop and inside a <% %>, so that''s why the >> question of <% puts 123 %> > > I think you should use something like: > > <% for x in y do %> > <%= "#{x.z}, #{x.a}" %> > <% end %>so for example... if i have the code <% begin t = '''' s = Iconv.conv("UTF-32", "UTF-8", some_utf8_string) (s.length / 4).times do |i| b3 = s[i*4 + 2] b4 = s[i*4 + 3] t += ("&#x" + "%02X" % b3) + ("%02X" % b4) + ";" end rescue => details t = "exception " + details end %> <%= t %> then if i don''t want to concat the output into t first... then would it be a bit messy to use <% begin t = '''' s = Iconv.conv("UTF-32", "UTF-8", some_utf8_string) (s.length / 4).times do |i| b3 = s[i*4 + 2] b4 = s[i*4 + 3] %> <%= ("&#x" + "%02X" % b3) + ("%02X" % b4) + ";" %> <% end rescue => details %> <%= "exception " + details %> <% end %> -- Posted via http://www.ruby-forum.com/.
putting this code into a helper method or partial will keep your views clean. http://api.rubyonrails.org/classes/ActionController/Helpers/ClassMethods.html http://api.rubyonrails.org/classes/ActionView/Partials.html On May 9, 8:36 am, Jian Lin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Alberto Santini wrote: > > Jian Lin wrote: > >> actually... sometimes i want to output multiple things inside of <% %>, > >> or put everything inside a loop and inside a <% %>, so that''s why the > >> question of <% puts 123 %> > > > I think you should use something like: > > > <% for x in y do %> > > <%= "#{x.z}, #{x.a}" %> > > <% end %> > > so for example... if i have the code > > <% > begin > t = '''' > s = Iconv.conv("UTF-32", "UTF-8", some_utf8_string) > > (s.length / 4).times do |i| > b3 = s[i*4 + 2] > b4 = s[i*4 + 3] > t += ("&#x" + "%02X" % b3) + ("%02X" % b4) + ";" > end > rescue => details > t = "exception " + details > end > %> > > <%= t %> > > then if i don''t want to concat the output into t first... then would it > be a bit messy to use > > <% > begin > t = '''' > s = Iconv.conv("UTF-32", "UTF-8", some_utf8_string) > > (s.length / 4).times do |i| > b3 = s[i*4 + 2] > b4 = s[i*4 + 3] > %> > > <%= ("&#x" + "%02X" % b3) + ("%02X" % b4) + ";" %> > > <% > end > rescue => details > %> > <%= "exception " + details %> > > <% > end > %> > -- > Posted viahttp://www.ruby-forum.com/.
I would suggest most of that should be in the controller not the view, you don''t want to be rescuing exceptions in the view. Colin 2009/5/9 Jian Lin <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > Alberto Santini wrote: > > Jian Lin wrote: > >> actually... sometimes i want to output multiple things inside of <% %>, > >> or put everything inside a loop and inside a <% %>, so that''s why the > >> question of <% puts 123 %> > > > > I think you should use something like: > > > > <% for x in y do %> > > <%= "#{x.z}, #{x.a}" %> > > <% end %> > > so for example... if i have the code > > <% > begin > t = '''' > s = Iconv.conv("UTF-32", "UTF-8", some_utf8_string) > > (s.length / 4).times do |i| > b3 = s[i*4 + 2] > b4 = s[i*4 + 3] > t += ("&#x" + "%02X" % b3) + ("%02X" % b4) + ";" > end > rescue => details > t = "exception " + details > end > %> > > <%= t %> > > then if i don''t want to concat the output into t first... then would it > be a bit messy to use > > > <% > begin > t = '''' > s = Iconv.conv("UTF-32", "UTF-8", some_utf8_string) > > (s.length / 4).times do |i| > b3 = s[i*4 + 2] > b4 = s[i*4 + 3] > %> > > <%= ("&#x" + "%02X" % b3) + ("%02X" % b4) + ";" %> > > <% > end > rescue => details > %> > <%= "exception " + details %> > > <% > end > %> > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---