Problema con variable en ruby on rails

30 views
Skip to first unread message

Esteban Penagos

unread,
Oct 15, 2014, 4:57:44 PM10/15/14
to rubyonra...@googlegroups.com
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

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Oct 15, 2014, 5:03:34 PM10/15/14
to rubyonra...@googlegroups.com
2014-10-15 21:56 GMT+01:00 Esteban Penagos <li...@ruby-forum.com>:
> 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" %>

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

>
> 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
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b7ce6710995325e98a6545e05ad37357%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Esteban Penagos

unread,
Oct 15, 2014, 6:00:07 PM10/15/14
to rubyonra...@googlegroups.com
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

Walter Lee Davis

unread,
Oct 18, 2014, 11:04:47 AM10/18/14
to rubyonra...@googlegroups.com

On Oct 15, 2014, at 5:58 PM, Esteban Penagos <li...@ruby-forum.com> 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

> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c2570f14b4cf87093988ee02b010c085%40ruby-forum.com.
Reply all
Reply to author
Forward
0 new messages