# Problema con variable en ruby on rails

**URL:** <https://www.ruby-forum.com/t/problema-con-variable-en-ruby-on-rails/232549>\
**Category:** Rails\
**Created:** [October 15, 2014, 10:56pm UTC](https://www.ruby-forum.com/t/problema-con-variable-en-ruby-on-rails/232549 "2014-10-15T22:56:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [October 15, 2014, 10:56pm UTC](https://www.ruby-forum.com/t/problema-con-variable-en-ruby-on-rails/232549/1 "2014-10-15T22:56:02Z")

</div>

Buenos Días, estoy haciendo una aplicación de pedidos en linea en Ruby  
On Rails y tengo un problema que no e podido solucionar

Mi problema son el manejo de las variables en rails.

uno de los inconvenientes es que tengo un (select\_tag) que lista los  
descuentos (0, 10, 15) que se le otorgara al cleinte y que se le  
aplicaran a el costo de los productos, pero primero no se como capturar  
el valor que el usuario eligió del (select\_tag) para restarlo al valor  
del producto y segundo no se como guardar ese valor en la base de datos,  
ya tengo un campo descuento.

el codigo que tengo es:

\<%= select\_tag “listadescuento”,options\_for\_select([“0”, “10”, “15”],  
“0” %\>

la pregunta como le asigno el valor que escogió el usuario a una  
variable  
o hay un método que me devuelva ese valor

gracias por su atencion

---

<div class="post-metadata">

**Author:** ![estebanxpj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/0ea827/32.png) [@estebanxpj](https://www.ruby-forum.com/u/estebanxpj)\
**Post date:** [October 15, 2014, 11:04pm UTC](https://www.ruby-forum.com/t/problema-con-variable-en-ruby-on-rails/232549/2 "2014-10-15T23:04:13Z")

</div>

2014-10-15 21:56 GMT+01:00 Esteban P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ya tengo un campo descuento.
> 
> el codigo que tengo es:
> 
> \<%= select\_tag “listadescuento”,options\_for\_select([“0”, “10”, “15”],  
> “0” %\>

I don’t understand your question but you have missed a closing  
parenthesis ‘)’ to match options\_for\_select( … so I would expect a  
syntax error to be shown.

Colin

---

<div class="post-metadata">

**Author:** ![estebanxpj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/0ea827/32.png) [@estebanxpj](https://www.ruby-forum.com/u/estebanxpj)\
**Post date:** [October 15, 2014, 11:58pm UTC](https://www.ruby-forum.com/t/problema-con-variable-en-ruby-on-rails/232549/3 "2014-10-15T23:58:29Z")

</div>

hi colin  
my problem is: I need to capture the value of \<% = select\_tag “list”,  
options\_for\_select ([“0”, “10”, “15”], “0”)%\>  
in a variable, to calculate the value of the product

conclucion the user chooses in the 0 or 10 or 15 and I need to capture  
that number as a variable

thank you very much

---

<div class="post-metadata">

**Author:** ![estebanxpj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/0ea827/32.png) [@estebanxpj](https://www.ruby-forum.com/u/estebanxpj)\
**Post date:** [October 18, 2014, 5:05pm UTC](https://www.ruby-forum.com/t/problema-con-variable-en-ruby-on-rails/232549/4 "2014-10-18T17:05:45Z")

</div>

On Oct 15, 2014, at 5:58 PM, Esteban P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> hi colin  
> my problem is: I need to capture the value of \<% = select\_tag “list”,  
> options\_for\_select ([“0”, “10”, “15”], “0”)%\>  
> in a variable, to calculate the value of the product
> 
> conclucion the user chooses in the 0 or 10 or 15 and I need to capture  
> that number as a variable
> 
> thank you very much

You would “capture” that value in your controller when you handle the  
form submitted by the user, so in your #create or #update methods.  
Whatever that form field is named will be submitted in the params hash,  
with the value set to their choice.

If you are talking about capturing the setting before they submit the  
form, then you are into the realm of JavaScript, and in Rails this is  
usually handled in an unobtrusive JS handler. Read up on Ajax and Rails  
for more details about that.

Walter
