Forum: Ruby on Rails How to take text_field value in a variable before form submit.

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.
4fe082e7f293fc244aab84b61a98d9a5?d=identicon&s=25 Jitendra Kushvaha (jitendrakush)
on 2016-11-14 06:50
Hello friends,

I am new in ruby on rails, I want to take text_field value in a variable
then this variable value, I want to pass controller method throw
form_for method.

_employee.html.erb file

<div class="mydata1">
    <%= text_field :offer_id, { class: 'form-control', id: 'offer_id' }
%>
</div>

<%= form_for :employee_details, :url =>{:controller => "hr", :action =>
"update", :offer_id =>2 } do |f| %>

  ------------ here my other code --------------------
<% end %>

I want to sent variable value in place ":offer_id => 2(variable value)".

JavaScript code on the same page:

<script type="text/javascript">

  // edit employee information
  $('#exampleModal1').on('show.bs.modal', function (event) {

    var button = $(event.relatedTarget)
    var offer_id = button.data('offer_id')

    var modal = $(this)
    modal.find('.mydata1 input').val(offer_id)

  });
</script>
This topic is locked and can not be replied to.