Search code examples
javascriptruby-on-railsrhtml

Getting a value from Javascript on Ruby


<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


Solution

  • 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.