0

[ポリシー] ビューで、テーブルからのすべてのエジェクティブを表示する選択ボックスを作成しようとしていますが、選択したエジェクティブからパラメーターを取得するための検索ボタンを作成する必要がejecutive_nameありますlast_name

私のモデルには関係があります:

class Policy < ActiveRecord::Base
  unloadable
  belongs_to :ejecutive
  has_many :policy 
end

class Ejecutive < ActiveRecord::Base
  has_many :policies
end

私のテーブルには次の関係がありejecutive_idます:

class CreateEjecutives < ActiveRecord::Migration
  def self.up
   create_table :ejecutives do |t|
     t.string :name,:null=>false
     t.string :lastname1,:null=>false
     t.timestamps
   end
  end

  def self.down
    drop_table :ejecutives
  end
end

class CreatePolicies < ActiveRecord::Migration
 def self.up
   create_table :policies do |t|
     t.string :num_policy, :null=>false
     t.integer :ejecutive_id
     t.timestamps
   end
 end

 def self.down
  drop_table :policies
 end
end

これは私のコントローラーです:

class PolicyManagement::PolicyController < ApplicationController
   @ejecutives = Ejecutive.find(:all)
   @policies = Policy.find(:all)
end  

これは私の見解です:

 Select Ejecutive:
 %= select_tag 'ejecutives',"<option value=\"\">Seleccione</option>"+options_for_select(@ejecutives.collect {|t| [t.name.to_s+" "+t.lastname1.to_s,t.id]})%>


 Results
  <% @policies.each do |policy| %>
  <p> <%= policy.num_policy%> </p>
  <p> <%= policy.ejecutive.name %> </p>
  <p> <%= policy.ejecutive.last_name %> </p>
  <% end %>

私はこれを試しました

<% form_tag :controller=>"policy_management/policy",:action =>"generate_print_ejecutive_comercial", :method => 'get' do %>
  <p>
  <%= text_field_tag :search,params[:search] %>
  <%= select_tag "Ejecutives", options_from_collection_for_select(@ejecutives, "id", "name") %>
   #Here i in select_tag "ejecutives" need to add searh params..
  <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>

Rails 2.3.5 を使用しています。

誰かがこの問題について知っていますか?助けていただければ幸いです。

4

1 に答える 1