All, In JSP, I can output strings in the Web page by either <%= foo %> //foo is a string or returns a string or <% out.write("test") %> //write directly to the output stream. What is the method of "writing to the output stream" in RoR? Basically, what is the equivalent of out.write()? I have an if then statement that I want to put around a call to h some_stuff Thanks, Wes -- Posted via http://www.ruby-forum.com/.
Not entirely sure what out.write() does (just outputs to the page, I guess?). If you want to conditionally display something though, do <%= h some_stuff if some_cond? %> If it''s a bit more complex you can do <% if some_cond? %> <%= h some_stuff %> <%= h some_other_stuff %> <% end %> <%= expression %> writes the result of expression to the page. Pat On 3/14/06, Wes Gamble <weyus@att.net> wrote:> All, > > In JSP, I can output strings in the Web page by either > > <%= foo %> //foo is a string or returns a string > or > <% out.write("test") %> //write directly to the output stream. > > What is the method of "writing to the output stream" in RoR? Basically, > what is the equivalent of out.write()? > > I have an if then statement that I want to put around a call to > > h some_stuff > > Thanks, > Wes > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I''m sure he knows what <%= expression %> does since he mentioned it first :) I don''t have an answer Wes, but I''ve wished for the same thing. Sometimes it is just aesthetically nicer to use something like out.write() in a <% %> code block. Perhaps it affects people who use color coded editors more... On 3/14/06, Pat Maddox <pergesu@gmail.com> wrote:> Not entirely sure what out.write() does (just outputs to the page, I > guess?). If you want to conditionally display something though, do > > <%= h some_stuff if some_cond? %> > > If it''s a bit more complex you can do > <% if some_cond? %> > <%= h some_stuff %> > <%= h some_other_stuff %> > <% end %> > > <%= expression %> writes the result of expression to the page. > > Pat > > > > On 3/14/06, Wes Gamble <weyus@att.net> wrote: > > All, > > > > In JSP, I can output strings in the Web page by either > > > > <%= foo %> //foo is a string or returns a string > > or > > <% out.write("test") %> //write directly to the output stream. > > > > What is the method of "writing to the output stream" in RoR? Basically, > > what is the equivalent of out.write()? > > > > I have an if then statement that I want to put around a call to > > > > h some_stuff > > > > Thanks, > > Wes > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Dav Yaginuma http://AkuAku.org/
Yeah, it just seems so cheesy to me to do <% if %> <%= stuff %> <% else %> <%= other stuff %> <% end %> especially since we _know_ there _must_ be some kind of handle to the output stream anyway. Actually, maybe not at the Ruby level - I don''t understand the IO model for Ruby yet, so I can''t say. But it seems like there should be some suitable abstraction, no? Anyhow, cheese is ok for now :) Wes Dav Yaginuma wrote:> I''m sure he knows what <%= expression %> does since he mentioned it > first :) > > I don''t have an answer Wes, but I''ve wished for the same thing. > Sometimes it is just aesthetically nicer to use something like > out.write() in a <% %> code block. Perhaps it affects people who use > color coded editors more... > > On 3/14/06, Pat Maddox <pergesu@gmail.com> wrote: >> >> > >> > >> > >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > Dav Yaginuma > http://AkuAku.org/-- Posted via http://www.ruby-forum.com/.
Wes Gamble wrote:> Yeah, it just seems so cheesy to me to do > > <% if %> > <%= stuff %> > <% else %> > <%= other stuff %> > <% end %> >Try: <%= if some_condition some_code_evaluating_to_a_string else some_other_string end %> That works because if actually returns a value... -- Alex
Wes Gamble
2006-Mar-14 21:30 UTC
[Rails] Re: Re: The RoR equivalent of out.write() in JSP?
Alex, Thanks - that makes a lot of sense. :) Wes Alex Young wrote:> Wes Gamble wrote: >> Yeah, it just seems so cheesy to me to do >> >> <% if %> >> <%= stuff %> >> <% else %> >> <%= other stuff %> >> <% end %> >> > Try: > > <%= if some_condition > some_code_evaluating_to_a_string > else > some_other_string > end %> > > That works because if actually returns a value...-- Posted via http://www.ruby-forum.com/.
On Mar 14, 2006, at 12:09 PM, Wes Gamble wrote:> All, > > In JSP, I can output strings in the Web page by either > > <%= foo %> //foo is a string or returns a string > or > <% out.write("test") %> //write directly to the output stream. > > What is the method of "writing to the output stream" in RoR? > Basically, > what is the equivalent of out.write()?you can use two ways to do this: <% _erbout << "foo" %> OR <% concat("foo", binding) %> Neither of which is very pretty ;)> > I have an if then statement that I want to put around a call to > > h some_stuff > > Thanks, > Wes > > > -- > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra@yakima-herald.com
Conditional expressions work: <%= (1==1) ? ''yep'' : ''nope'' %> <%= (1==2) ? ''yep'' : ''nope'' %> Joe -- Posted via http://www.ruby-forum.com/.
On Tue, 14 Mar 2006 21:09:36 +0100, Wes Gamble wrote:> What is the method of "writing to the output stream" in RoR? Basically, > what is the equivalent of out.write()? > > I have an if then statement that I want to put around a call toUsually, when I''ve wanted to do that, I realized that the view was actually getting too complicated, and the code really belonged in either the model or a helper... I''m not saying that''s always the case, but it''s something to consider. Jay Levitt