Window.open of JavaScript is acting before it gets to the Rails controller -


in rails controller have this:

def index   provider_id = params[:provider] ||= 'all'   thera_class = params[:therapeutic_class] ||= 'all'   med_name = params[:medication_name] ||= 'all' 

in javascript side passing these params url query params when gets called goes index action method:

window.open("http://localhost:3000/pharmacy/patients?provider="+provider_id+"&"+"therapeutic_class="+thera_class+"&"+"medication_name="+medication_name); 

the problem javascript values passing if don't have value , undefined passed undefined.

i more concerned know architecturally wrong doing this? "rails way" of doing it? specially routing javascript rails controller , passing params need architectural input.

when fetch infos on client side javascript, guess initialize variables provider_id, therapeutic_class, etc. this:

var provider_id = $('#provider').val(); var thera_class = $('#therapeutic_class').val(); # etc. # , do: window.open("http://localhost:3000/pharmacy/patients?provider="+provider_id+"&"+"therapeutic_class="+thera_class+"&"+"medication_name="+medication_name); 

if yes, suggest so:

var url = "http://localhost:3000/pharmacy/patients?"; var params = { }; var params_names = [ 'provider', 'therapeutic_class', 'medication_name' ]; $.each(params_names, function(i, param_name) {   var value = $('#'+param_name).val();   if(value !== undefined && value != '') {     params[param_name] = value;   } }) $.each(params, function(key, value) {   url += key + "=" + value + "&"; }) window.open(url) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -