Greg Hauptmann
2007-May-19 10:08 UTC
how to output HTML in a view within a <% %> (not a <%= %> )
Hi, How can I output/render text within a view, but within a block of ruby code that is surrounded by <% %> ? I know that use of <%= %> works, but if I have several lines of ruby in the view that is within <% %> and I want to output text to be part of the HTML how can I do this? For example something like "puts" or "render" but actually works within a *.rthml view. Thanks Greg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Remco Van ''t veer
2007-May-19 12:17 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %
The following: <% _erbout += Time.now %> and <% concat Time.now, binding %> are the same as: <%= Time.now %> Greg Hauptmann wrote:> How can I output/render text within a view, but within a block of ruby > code that is surrounded by <% %> ?-- 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 -~----------~----~----~----~------~----~------~--~---
Florian Gilcher
2007-May-19 12:32 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %
While this is the way to do it, I would suggest writing multi-line ruby code as a helper and to return the HTML-Code. Something like this: -- module YourControllerHelper def my_output(model) name = strip_tags(model.name) description = strip_tags(model.description) html = <<HTML <h1>#{name}</h1> <p>#{description}</p> HTML end end View: <%= my_output %> -- Another version is to substitute the here_doc with a render-call using a partial. There are multiple versions to accomplish this, but the above is the quickest to write ;). Remco Van ''t veer wrote:> The following: > > <% _erbout += Time.now %> > > and > > <% concat Time.now, binding %> > > are the same as: > > <%= Time.now %> > > > Greg Hauptmann wrote: > >> How can I output/render text within a view, but within a block of ruby >> code that is surrounded by <% %> ?-- 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 -~----------~----~----~----~------~----~------~--~---
Ian Leitch
2007-May-19 20:22 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %> )
<% @foo.each do |bar| %> <b> <%= bar %> </b> <% end %> On 19/05/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > How can I output/render text within a view, but within a block of ruby > code that is surrounded by <% %> ? > > I know that use of <%= %> works, but if I have several lines of ruby in > the view that is within <% %> and I want to output text to be part of the > HTML how can I do this? > > For example something like "puts" or "render" but actually works within a > *.rthml view. > > Thanks > Greg > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-May-19 20:24 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %> )
tks Ian - so it sounds like what I''m asking isn''t possible? (i.e. and you do have to break the script area back to HTML, if you know what I mean) On 5/20/07, Ian Leitch <port001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > <% @foo.each do |bar| %> > <b> > <%= bar %> > </b> > <% end %> > > On 19/05/07, Greg Hauptmann < greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > How can I output/render text within a view, but within a block of ruby > > code that is surrounded by <% %> ? > > > > I know that use of <%= %> works, but if I have several lines of ruby in > > the view that is within <% %> and I want to output text to be part of the > > HTML how can I do this? > > > > For example something like "puts" or "render" but actually works within > > a *.rthml view. > > > > Thanks > > Greg > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ian Leitch
2007-May-19 20:48 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %> )
what exactly are you trying to do? Give me an example. On 19/05/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > tks Ian - so it sounds like what I''m asking isn''t possible? (i.e. and you > do have to break the script area back to HTML, if you know what I mean) > > On 5/20/07, Ian Leitch <port001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > <% @foo.each do |bar| %> > > <b> > > <%= bar %> > > </b> > > <% end %> > > > > On 19/05/07, Greg Hauptmann < greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi, > > > > > > How can I output/render text within a view, but within a block of ruby > > > code that is surrounded by <% %> ? > > > > > > I know that use of <%= %> works, but if I have several lines of ruby > > > in the view that is within <% %> and I want to output text to be part of > > > the HTML how can I do this? > > > > > > For example something like "puts" or "render" but actually works > > > within a *.rthml view. > > > > > > Thanks > > > Greg > > > > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Mear
2007-May-19 22:00 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %> )
Remco gave you the answer: use the concat method. Stylistically, though, you should only use the concat if it''s truly unavoidable. In general, you shouldn''t be putting too much Ruby code into your views. As Florian suggests, think about pushing this out to a helper so that you can use the clean, readable <%= %> tags. Chris On May 19, 9:24 pm, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> tks Ian - so it sounds like what I''m asking isn''t possible? (i.e. and you do > have to break the script area back to HTML, if you know what I mean) > > On 5/20/07, Ian Leitch <port...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > <% @foo.each do |bar| %> > > <b> > > <%= bar %> > > </b> > > <% end %> > > > On 19/05/07, Greg Hauptmann < greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > How can I output/render text within a view, but within a block of ruby > > > code that is surrounded by <% %> ? > > > > I know that use of <%= %> works, but if I have several lines of ruby in > > > the view that is within <% %> and I want to output text to be part of the > > > HTML how can I do this? > > > > For example something like "puts" or "render" but actually works within > > > a *.rthml view. > > > > Thanks > > > Greg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-May-19 22:41 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %> )
oh...I didn''t see a response from Remco yet(?) I''m basically just curious to understand whether it was possible to output from within <% %>, to relate possible use within rails views with Java JSP. The answer seems to be that it is not possible, which is fine, I just wanted to understand. So you have to do: <% @foo.each do |bar| %> <%= bar %> <% end %> As there is no way of doing something like: <% @foo.each do |bar| render_to_view bar end %> tks Greg On 5/20/07, Chris Mear <chris-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote:> > > Remco gave you the answer: use the concat method. > > Stylistically, though, you should only use the concat if it''s truly > unavoidable. In general, you shouldn''t be putting too much Ruby code > into your views. As Florian suggests, think about pushing this out to > a helper so that you can use the clean, readable <%= %> tags. > > Chris > > On May 19, 9:24 pm, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > tks Ian - so it sounds like what I''m asking isn''t possible? (i.e. and > you do > > have to break the script area back to HTML, if you know what I mean) > > > > On 5/20/07, Ian Leitch <port...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > <% @foo.each do |bar| %> > > > <b> > > > <%= bar %> > > > </b> > > > <% end %> > > > > > On 19/05/07, Greg Hauptmann < greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi, > > > > > > How can I output/render text within a view, but within a block of > ruby > > > > code that is surrounded by <% %> ? > > > > > > I know that use of <%= %> works, but if I have several lines of > ruby in > > > > the view that is within <% %> and I want to output text to be part > of the > > > > HTML how can I do this? > > > > > > For example something like "puts" or "render" but actually works > within > > > > a *.rthml view. > > > > > > Thanks > > > > Greg > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Lionel Bouton
2007-May-19 22:56 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %> )
Greg Hauptmann wrote the following on 20.05.2007 00:41 :> oh...I didn''t see a response from Remco yet(?) > > I''m basically just curious to understand whether it was possible to > output from within <% %>, to relate possible use within rails views > with Java JSP. The answer seems to be that it is not possible, which > is fine, I just wanted to understand. > > So you have to do: > <% @foo.each do |bar| %> > <%= bar %> > <% end %> > > As there is no way of doing something like: > <% > @foo.each do |bar| > render_to_view bar > end > %> >No, in fact the first code is roughly translated to the second version using _erbout (or maybe concat). Nothing prevents you to directly using it : <% @foo.each do |bar| _erbout += bar end %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-May-20 00:02 UTC
Re: how to output HTML in a view within a <% %> (not a <%= %> )
ok thanks Lionel - I''ve understood the concat method too. Seems like concat would be the slightly less "under the bonnet" approach to use. Neither seemed to get mentioned in the "Agile Web Development with Rails" book in this context which is interesting. On 5/20/07, Lionel Bouton <lionel-subscription-WTamNBQcZIx7tPAFqOLdPg@public.gmane.org> wrote:> > > Greg Hauptmann wrote the following on 20.05.2007 00:41 : > > oh...I didn''t see a response from Remco yet(?) > > > > I''m basically just curious to understand whether it was possible to > > output from within <% %>, to relate possible use within rails views > > with Java JSP. The answer seems to be that it is not possible, which > > is fine, I just wanted to understand. > > > > So you have to do: > > <% @foo.each do |bar| %> > > <%= bar %> > > <% end %> > > > > As there is no way of doing something like: > > <% > > @foo.each do |bar| > > render_to_view bar > > end > > %> > > > > No, in fact the first code is roughly translated to the second version > using _erbout (or maybe concat). Nothing prevents you to directly using it > : > > <% > @foo.each do |bar| > _erbout += bar > end > %> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---