ruby on rails - passing parameter in jquery auto complete -


i'm trying implement auto complete in rails application. i'm trying pass ruby parameter via source of jquery. here i'm trying do.

$( "#text" ).autocomplete({ appendto: "#searchwrapper1", source:  h_url+"product_details/menu_search_auto/" + <%= "'#{params[:deptid]}'" %> , open:function() {         $(".ui-autocomplete").mcustomscrollbar1({             set_width : false,             set_height : false,              horizontalscroll : false,              scrollinertia : 550,              scrolleasing : "easeoutcirc",              mousewheel : "auto",              autodraggerlength : true,              scrollbuttons : {                 enable : false,                  scrolltype : "continuous",                  scrollspeed : 20,                  scrollamount : 40              },          } 

here route.rb file

match "/product_details/menu_search_auto/:deptid"=>'product_details#menu_search_auto' 

and controller part is:

def menu_search_auto     list=[]     if(params[:deptid].to_s == 'all')       b1=test4.where("name ?","#{params[:term]}%")     else       case params[:deptid].to_i       when 1         b1=test1.where("name ?","#{params[:term]}%")       when 2         b1=test2.where("name ?","#{params[:term]}%")       when 3         b1=test3.where("name ?","#{params[:term]}%")       else       end     end      b1.each |b1|       list << {"label"=>b1.name, "value"=>b1.name, "id"=>b1.id}     end       respond_to |format|       format.json{render :json=>list.to_json, :layout=>false}     end   end 

but neither i'm able pass parameter nor i'm getting error.

please suggest me i'm going wrong??

i suppose code obtain @ post in view js(.coffee) extension.

the way wrote it, "<%=" stuff recognized js code.

try following.

in controller:

def an_action   @foo = "something"   respond_to |format|     format.js   end  end 

and in view:

source:  h_url+"product_details/menu_search_auto/<%= j("#{@foo}") %>" 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -