javascript - Rails 4 - Sending Google Maps API JSON return val to controller -


i'm using google maps javascript api return distance point point b , i'm able value. i'm able see writing log (using google chrome devtools) using following js:

console.log(totaldistance); 

what i've tried far has not worked far have hidden tag , set value of using js:

$('#distance').text(totaldistance); 

in view form have is:

<%= form_tag({ :action => 'fare', :controller=> 'page'}, {:class => 'form-horizontal center'}) %>    <%= text_field_tag :origin, '', class: 'form-control', id: 'origin-input' %><br/>    <%= text_field_tag :destination, '', class: 'form-control', id: 'destination-input' %>    <%= hidden_field_tag :distance, '', id: 'distance' %>    <%= submit_tag "submit" , id: 'get-route'%><!-- id needed js --> <% end %> 

my thought pass value on parameter controller i'm checking params passed on through view this:

<pre> <% params.each |key, value| %>   <%= key + "==>" + value + "\n" %> <% end %> </pre> 

the output such:

    utf8==>✓      authenticity_token==>**omitted**      origin==>laguardia airport, ny, united states      destination==>jfk airport, ny, united states      distance==>      commit==>submit      controller==>page      action==>fare 

but can see parameter 'distance' not have value goes on controller. but see value of totaldistance in log

so need figuring out should in action of controller, if javascript needs changed else , in view if should change anything. feel i'm not doing correctly.

1 thing have noticed when trying different things, trying set div id of "distance" value of totaldistance , when hit submit on form, div show correct distance and, since have page reloading right now, value not stay once page reloaded.

i know how assign instance variables in controller parameters , accessing them in view. not issue here.

if using hidden input field. might want use

$('#distance').val(totaldistance) 

as, trying assign text; might not work. and, have use .val() set/get value input fields.

refer:

  1. http://api.jquery.com/val/
  2. http://api.jquery.com/text/

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -