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

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>
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.