Forum: Ruby on Rails The RoR equivalent of out.write() in JSP?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-14 21:09
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
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-03-14 21:21
(Received via mailing list)
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
26c0295207079d1189aea43869e3eaea?d=identicon&s=25 Dav Yaginuma (Guest)
on 2006-03-14 21:51
(Received via mailing list)
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/
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-14 22:02
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/
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-03-14 22:12
(Received via mailing list)
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...
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-14 22:30
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...
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-03-14 22:56
(Received via mailing list)
On Mar 14, 2006, at 12:09 PM, Wes Gamble wrote:

> 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 ;)


>
> _______________________________________________
> 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
429500a5a54600958c9c7ac032a37f66?d=identicon&s=25 Joe (Guest)
on 2006-03-14 23:02
Conditional expressions work:

<%= (1==1) ? 'yep' : 'nope' %>
<%= (1==2) ? 'yep' : 'nope' %>


Joe
A63764f318f10379c8b51349b757cf4b?d=identicon&s=25 Jay Levitt (Guest)
on 2006-03-15 02:21
(Received via mailing list)
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 to

Usually, 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
This topic is locked and can not be replied to.