Note that there are some explanatory texts on larger screens.

plurals
  1. POText field tag search issue
    text
    copied!<p>Hello everybody i'm trying to search a column from another table with id hide using text_field_tag</p> <p>In my view policy_vehicles i have text_field_tag and want to search by motor</p> <p>My tables</p> <pre><code>Vehicles |id| |motor| |plate| integer varchar(255) varchar(255) 1 MOTOR1 PLATE1 2 MOTOR2 PLATE2 3 MOTOR3 PLATE3 Policy_vehicles |id| |vehicle_id| integer integer 1 1 2 2 3 3 4 2 </code></pre> <p>Here is my controller</p> <pre><code>class PolicyManagement::PolicyController &lt; ApplicationController def generate_print_per_vehicle @motor =Vehicle.find(:all,:conditions=&gt;['motor =?' ,params[:search_motor] ] ) @policies= PolicyVehicle.find(:all,:conditions=&gt;['vehicle_id= ?',params[:search_motor] ] ) end end </code></pre> <p>Here is my model</p> <pre><code>class PolicyVehicle &lt; ActiveRecord::Base belongs_to :vehicle end class Vehicle &lt; ActiveRecord::Base has_many :policy_vehicles end </code></pre> <p>Here is my view where i'm trying to find by a column from another table</p> <pre><code>&lt;% form_tag :controller=&gt;"policy_management/policy",:action=&gt;"generate_print_per_vehicle" do %&gt; Motor: &lt;%= text_field_tag "search_motor",params[:search_motor] %&gt; &lt;%= submit_tag "Buscar", :name =&gt; nil %&gt; &lt;% end %&gt; </code></pre> <p>My logs</p> <pre><code> Vehicle Load (0.1ms) SELECT * FROM `vehicles` WHERE (motor ='4D56UCCR5811') PolicyVehicle Load (0.3ms) SELECT * FROM `policy_vehicles` WHERE (vehicle_id= '4D56UCCR5811') </code></pre> <p>It should be search like this</p> <pre><code> SELECT * FROM `vehicles` WHERE (motor ='4D56UCCR5811' and id =1) SELECT * FROM `policy_vehicles` WHERE (vehicle_id= '1') </code></pre> <p>I tried this but is not working</p> <pre><code> #controller @vehicle = Vehicle.find(:all,:conditions=&gt;['motor =?' ,params[:search_motor] ]) @policies = PolicyVehicle.find(:all, :conditions =&gt; ['vehicle_id = ? ', @vehicle.id]) #logs Vehicle Load (17.2ms) SELECT * FROM `vehicles` WHERE (motor ='4D56UCCR5811') PolicyVehicle Load (0.3ms) SELECT * FROM `policy_vehicles` WHERE (vehicle_id = 70353663367520 ) </code></pre> <p>Well i did a select_tag, but i want to write the motor, not select like this</p> <pre><code>&lt;%= select_tag "search_motor",options_for_select(@vehicle.collect {|t| [t.motor.to_s ,t.id]}, params[:search_motor].to_i ) %&gt; </code></pre> <p>Please someone can help me ? I will really appreciate help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload