Forum: Ruby on Rails PHP string + value to RoR

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.
6965b2e156b141d6807b5b70f564df29?d=identicon&s=25 Johnroy W. (johnroyworld)
on 2009-02-04 07:07
hello I'm new to RoR and i have concern regarding on how to output a
string with a value that parse on it.

Example in php:
 $value = 1;
 $string = 'the value is '.$value.'.';

and it gives you the output which is: "the value is 1." so how we are
going to do it in RoR. Any help would be appreciated. I know its very
simple to the one who knows it. Forgive me im only a newbie. Thank you!
Darrik Mazey (Guest)
on 2009-02-04 07:11
(Received via mailing list)
Johnroy World wrote:
> hello I'm new to RoR and i have concern regarding on how to output a
> string with a value that parse on it.
>
> Example in php:
>  $value = 1;
>  $string = 'the value is '.$value.'.';
>
> and it gives you the output which is: "the value is 1." so how we are
> going to do it in RoR. Any help would be appreciated. I know its very
> simple to the one who knows it. Forgive me im only a newbie. Thank you!

myvalue = 1
mystring = 'the value is ' + myvalue.to_s + '.'

Cheers,
Darrik

--
Darrik Mazey
Developer
DMT Programming, LLC.
P.O. Box 91
Torrington, CT 06790
office: 330.983.9941
    fax: 330.983.9942
mobile: 330.808.2025
darrik@dmtprogramming.com

To obtain my public key, send an email to
darrik@publickey.dmtprogramming.com.
D654f89d46f05edf3dddee6d37c709a9?d=identicon&s=25 Joshua A. (joshnabbott)
on 2009-02-04 07:30
Or use interpolation with double-quotes:

myvalue = 1
mystring = "the value is #{myvalue.to_s}."

-- Josh
http://iammrjoshua.com


Darrik Mazey wrote:
> Johnroy World wrote:
>> hello I'm new to RoR and i have concern regarding on how to output a
>> string with a value that parse on it.
>>
>> Example in php:
>>  $value = 1;
>>  $string = 'the value is '.$value.'.';
>>
>> and it gives you the output which is: "the value is 1." so how we are
>> going to do it in RoR. Any help would be appreciated. I know its very
>> simple to the one who knows it. Forgive me im only a newbie. Thank you!
>
> myvalue = 1
> mystring = 'the value is ' + myvalue.to_s + '.'
>
> Cheers,
> Darrik
>
> --
> Darrik Mazey
> Developer
> DMT Programming, LLC.
> P.O. Box 91
> Torrington, CT 06790
> office: 330.983.9941
>     fax: 330.983.9942
> mobile: 330.808.2025
> darrik@dmtprogramming.com
>
> To obtain my public key, send an email to
> darrik@publickey.dmtprogramming.com.
2657252de9332d224554e2a80fd72540?d=identicon&s=25 Ryan B. (ryan-bigg)
on 2009-02-04 09:31
(Received via mailing list)
<% value = 1 %>
The value is <%= value %>

Read the getting started guide on http://guides.rubyonrails.com and
that will teach you a lot



On 04/02/2009, at 16:07, Johnroy World <rails-mailing-list@andreas-
F43889f0b3a9fbb7157ba9233bddd0ce?d=identicon&s=25 Robert W. (robert4723)
on 2009-02-04 17:36
Ryan Bigg wrote:
> <% value = 1 %>
> The value is <%= value %>

or
<% value = 1 %>
The value is <%= h(value) %>

In case you don't trust the "value" of value. The h (http_escape) method
will help protect you against injection attacks.
F43889f0b3a9fbb7157ba9233bddd0ce?d=identicon&s=25 Robert W. (robert4723)
on 2009-02-04 17:38
Robert Walker wrote:
> The value is <%= h(value) %>

Oops! Previous post was a bad example. Assume value was taken from user
input, which in that case you should escape it to make it safe.
This topic is locked and can not be replied to.