0
<td class="run_time"><%= l.text_field :run_time, :class => "line_item_run_time" %></td>

Hello.

I have rhtml code, l.text_field :run_time, has a value in its textbox that I need to use and I want to store it in a variable, if for example I do variable = l.text_field :run_time, it is going to save the whole object, the textbox with the value inside. Right now I just need the number that is inside.

Could you please tell me how can I do this it Ruby. Thanks

Luis Vivas
  • 51
  • 1
  • 6

2 Answers2

0

If its a textfield, it would be part of a form, which you will eventually post to the server, sending to the server all the data for the fields in the form.
The call may be a redirect_call or an AJAX call, but the data would be sent to the server.
The action that you send the data to, will receive the data in a params hash, and then you can get the value of the text field.

Jatin Ganhotra
  • 6,825
  • 6
  • 48
  • 71
0

It's not clear what you're asking for, but if you want the value from the object, what you might want is this:

variable = l.object.run_time

That calls the run_time method on the currently bound form object l.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • Thank you Tadman. I am trying to get the value that is there. I am going to try with this but perhaps it only works with the java script. I wanted to pass this value from javascript to a variable in Ruby on rails but I think this is not possbile, any way, if this command gives me the value I think I can use it. – Luis Vivas May 02 '11 at 17:09
  • If you want to go from Ruby to JavaScript you need to send it back to the browser as a response. If you want to send it from JavaScript to Ruby you need to submit it as part of a request. This is just how HTTP works. – tadman May 02 '11 at 20:42