Filip Godsmurf
2006-Feb-23 16:29 UTC
[Rails] how to output something from within <% %> tags?
simple question: how do I output something from within <% %> tags? e.g. like ''echo'' in PHP. I thought it would be ''puts'' or ''print'' but neither seems to work. right now I always close the %> and open a <%= which is tedious. -- Posted via http://www.ruby-forum.com/.
Clint Pidlubny
2006-Feb-23 16:36 UTC
[Rails] how to output something from within <% %> tags?
You would use <% render :text => "whatever you want to write" %> but I''m not sure how that would be less tedious than <%= "whatever you want to write" %> On 2/23/06, Filip Godsmurf <krommenaas@gmail.com> wrote:> > simple question: how do I output something from within <% %> tags? e.g. > like ''echo'' in PHP. I thought it would be ''puts'' or ''print'' but neither > seems to work. right now I always close the %> and open a <%= which is > tedious. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060223/7efd61ed/attachment.html
Simo Gal
2006-Feb-23 16:48 UTC
[Rails] Re: how to output something from within <% %> tags?
Filip Godsmurf wrote:> simple question: how do I output something from within <% %> tags? e.g. > like ''echo'' in PHP. I thought it would be ''puts'' or ''print'' but neither > seems to work. right now I always close the %> and open a <%= which is > tedious.>From API docs:concat(string, binding) The regular puts and print are outlawed in eRuby. It?s recommended to use the <%= "hello" %> form instead of print "hello". If you absolutely must use a method-based output, you can use concat. It?s used like this: <% concat "hello", binding %>. Notice that it doesn?t have an equal sign in front. Using <%= concat "hello" %> would result in a double hello. Simo Addsw.it -- Posted via http://www.ruby-forum.com/.
Filip Godsmurf
2006-Feb-23 17:01 UTC
[Rails] Re: how to output something from within <% %> tags?
Clint Pidlubny wrote:> You would use <% render :text => "whatever you want to write" %> but I''m > not > sure how that would be less tedious than <%= "whatever you want to > write" %>Thanx but that doesn''t work; render :text only works from within the controller and it won''t render anything else anymore. I just need a command to echo stuff within a view. With an echo command I could do this: <% code echo "whatever you want to write" more code %> Whereas now I have to do this: <% code %> <%= "whatever you want to write" %> <% more code %> And that is very tedious. An echo command is so basic, surely RoR has this? -- Posted via http://www.ruby-forum.com/.
Filip Godsmurf
2006-Feb-23 17:16 UTC
[Rails] Re: how to output something from within <% %> tags?
Simo Gal wrote:> From API docs: > concat(string, binding) > > The regular puts and print are outlawed in eRuby. It?s recommended to > use the <%= "hello" %> form instead of print "hello". If you absolutely > must use a method-based output, you can use concat. It?s used like this: > <% concat "hello", binding %>. Notice that it doesn?t have an equal sign > in front. Using <%= concat "hello" %> would result in a double hello.Thanx, that works but the ", binding" part makes it bad. I tried to put this in application_helper.rb def echo(str) concat(str, binding) end but that generates an error undefined local variable or method `_erbout'' for #<#<Class:0x384b968>:0x384b548> Sometimes RoR annoys the hell out of me. Why would they deliberately ''outlaw'' a most basic function? -- Posted via http://www.ruby-forum.com/.
Hogan, Brian P.
2006-Feb-23 17:19 UTC
[Rails] Re: how to output something from within <% %> tags?
Helpers are meant for this. That''s why they exist. You put your output code in the helper function and call it in your view. That''s probably why they disabled it.... It forces you to keep your views cleaner. -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Filip Godsmurf Sent: Thursday, February 23, 2006 11:02 AM To: rails@lists.rubyonrails.org Subject: [Rails] Re: how to output something from within <% %> tags? Clint Pidlubny wrote:> You would use <% render :text => "whatever you want to write" %> but > I''m > not > sure how that would be less tedious than <%= "whatever you want to > write" %>Thanx but that doesn''t work; render :text only works from within the controller and it won''t render anything else anymore. I just need a command to echo stuff within a view. With an echo command I could do this: <% code echo "whatever you want to write" more code %> Whereas now I have to do this: <% code %> <%= "whatever you want to write" %> <% more code %> And that is very tedious. An echo command is so basic, surely RoR has this? -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Filip Godsmurf
2006-Feb-23 17:35 UTC
[Rails] RE: Re: how to output something from within <% %> tags?
Hogan, Brian P. wrote:> Helpers are meant for this. That''s why they exist. You put your output > code in the helper function and call it in your view. That''s probably > why they disabled it.... It forces you to keep your views cleaner.er, so what helper code do I need? as I said, the one I tried gave me an error. and being forced to use <%= is just making my views messier, cfr. my example. -- Posted via http://www.ruby-forum.com/.
Erik van Oosten
2006-Feb-23 17:37 UTC
[Rails] Re: how to output something from within <% %> tags?
It is simple. Where would puts output to? My guess is it would go to stdout, so to the webrick console? Erik. Filip Godsmurf schreef:> Simo Gal wrote: > > Sometimes RoR annoys the hell out of me. Why would they deliberately > ''outlaw'' a most basic function? > >
Kevin Olbrich
2006-Feb-23 17:48 UTC
[Rails] RE: Re: how to output something from within <% %> tags?
Just stuff all that messy logic into a helper and call that instead of <% code more code output something %> you could do <%= fancy_helper %> where fancy_helper is def fancy_helper code more code output something end _Kevin if that doesn''t do the trick, try posting some real code from your view and I''m sure we could find a way to clean it up. On Thursday, February 23, 2006, at 6:35 PM, Filip Godsmurf wrote:>Hogan, Brian P. wrote: >> Helpers are meant for this. That''s why they exist. You put your output >> code in the helper function and call it in your view. That''s probably >> why they disabled it.... It forces you to keep your views cleaner. > >er, so what helper code do I need? as I said, the one I tried gave me an >error. and being forced to use <%= is just making my views messier, cfr. >my example. > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-- Posted with http://DevLists.com. Sign up and save your time!
Hogan, Brian P.
2006-Feb-23 18:24 UTC
[Rails] RE: Re: how to output something from within <% %> tags?
Open up one of the files in app/Helpers like application_helper.rb and put this in def put_some_output(foo) "here''s the output of my method with the parameter #{foo} inline<br />" "here''s some more output<br />" end Then call that from your page <%=put_some_output "bar" %> -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Filip Godsmurf Sent: Thursday, February 23, 2006 11:36 AM To: rails@lists.rubyonrails.org Subject: [Rails] RE: Re: how to output something from within <% %> tags? Hogan, Brian P. wrote:> Helpers are meant for this. That''s why they exist. You put your output> code in the helper function and call it in your view. That''s probably > why they disabled it.... It forces you to keep your views cleaner.er, so what helper code do I need? as I said, the one I tried gave me an error. and being forced to use <%= is just making my views messier, cfr. my example. -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Ezra Zygmuntowicz
2006-Feb-23 21:11 UTC
[Rails] Re: how to output something from within <% %> tags?
On Feb 23, 2006, at 9:01 AM, Filip Godsmurf wrote:> Clint Pidlubny wrote: >> You would use <% render :text => "whatever you want to write" %> >> but I''m >> not >> sure how that would be less tedious than <%= "whatever you want to >> write" %> > > Thanx but that doesn''t work; render :text only works from within the > controller and it won''t render anything else anymore. I just need a > command to echo stuff within a view. > > With an echo command I could do this: > > <% > code > echo "whatever you want to write" > more code > %> > > Whereas now I have to do this: > > <% > code > %> > <%= "whatever you want to write" %> > <% > more code > %> > > And that is very tedious. > > An echo command is so basic, surely RoR has this?Also instead of concat you can use _erbout if you dont like the binding part. But I agree with others that its bad fomr to need this much code in your views. This in not PHP so you dont use echo or print. But if you must then you can use _erbout like this: <% code _erbout << "Some text" more code %> Cheers- -Ezra
Alex Young
2006-Feb-24 09:23 UTC
[Rails] Re: how to output something from within <% %> tags?
Filip Godsmurf wrote:> Thanx, that works but the ", binding" part makes it bad. I tried to put > this in application_helper.rb > > def echo(str) > concat(str, binding) > end > > but that generates an error > > undefined local variable or method `_erbout'' for > #<#<Class:0x384b968>:0x384b548>That''s because if you put it in a helper method, the binding is picked up from inside the helper method, which knows nothing about the variables local to the erb script. If you''re going to be using that technique, the binding() method actually has to be called in the erb.> > Sometimes RoR annoys the hell out of me. Why would they deliberately > ''outlaw'' a most basic function?Because it''s wrong to use it more often than it''s right, maybe? -- Alex
Superbiji
2006-Feb-24 09:51 UTC
[Rails] Re: how to output something from within <% %> tags?
On 2/24/06, Filip Godsmurf <krommenaas@gmail.com> wrote:> Clint Pidlubny wrote: > > You would use <% render :text => "whatever you want to write" %> but I''m > > not > > sure how that would be less tedious than <%= "whatever you want to > > write" %> > > Thanx but that doesn''t work; render :text only works from within the > controller and it won''t render anything else anymore. I just need a > command to echo stuff within a view. > > With an echo command I could do this: > > <% > code > echo "whatever you want to write" > more code > %> > > Whereas now I have to do this: > > <% > code > %> > <%= "whatever you want to write" %> > <% > more code > %> > > And that is very tedious. > > An echo command is so basic, surely RoR has this?I also really hate this, why there is no "echo" in rails But I did this, <%s = "" code s = s + "append something" code s %> -- Jual Beli Gratis egold 1$ http://shegold.com/