ruby - Pass select_tag value to load query in the same view rails -


i know question has been answered before, none of methods had worked me.

i have view select_tag loads options database.
<%= select_tag :nom, options_from_collection_for_select(usuario.all, :id, :tienda), prompt: "seleccionar tienda" %>

then, use link_to <%= link_to("cargar", :action => 'rel') %><br>to load query on controller

def rel @nom = params[:nom] @tie = av.find_by_sql(["select * avm.avs usuario_id in(select id avm.usuarios tienda = ?)", @nom]) render('rel') 

the problem when select value on select_tag not pass value , sets value nil...

i used collection_select , doesn't work either. <%= collection_select(:tienda, :tienda, usuario.all, :id, :tienda)%>

i broke head off trying figure out why. in advance!

use form_tag:

<%= form_tag action: rel %>   <%= select_tag :nom, options_from_collection_for_select(usuario.all, :id, :tienda), prompt: "seleccionar tienda" %>   <br>   <%= link_to("cargar", '#', onclick: 'this.parentnode.submit(); return false') %> <% end %> 

hint: replace find_by_sql arel:

@tie = av.where("usuario_id in (#{usuario.select('id').where('tienda = ?', @nom).to_sql})") 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -