Ruby on rails 使用选择框显示rails中的特定行

Ruby on rails 使用选择框显示rails中的特定行,ruby-on-rails,git,Ruby On Rails,Git,我有三种模式:设计、员工、分公司 class Employe < ActiveRecord::Base belongs_to :designation has_one :branch end class Designation < ActiveRecord::Base end class Branch < ActiveRecord::Base belongs_to :employe end class Employe

我有三种模式:设计、员工、分公司

 class Employe < ActiveRecord::Base
   belongs_to :designation
   has_one :branch
 end

 class Designation < ActiveRecord::Base

 end
  class Branch < ActiveRecord::Base
   belongs_to :employe
  end
class Employe
我已在我的员工窗体中声明了一个选择框,用于从指定模型中选择指定。现在我希望在分支中的一个选择框显示指定为经理的员工。我的分支窗体为

   <div class="field">
    <%= f.label :branch_address %><br>
   <%= f.text_field :branch_address ,class: "form-control"  
   ,placeholder: "Enter Branch Address"%>
   </div>
   <div class="field">
    <%= f.label :employe_id %><br>
   <%= f.select :employe_id,Employe.all.map{|e| [e.e_name,e.id]} %>
  </div><br>




这里是我的选择框中所有员工的列表。bt我只想要指定为经理的员工。在选择框中添加什么?plz帮助是rails的新功能

在员工模型中编写此定义

class Employe < ActiveRecord::Base
  def self.manager_list
     self.joins(:designation).where('designations.title = ?', 'manager').map{|e| [e.e_name,e.id]}
  end
end
class Employe
把这个写在你的视图中

<div class="field">
 <%= f.label :employe_id %><br>
 <%= f.select :employe_id,Employe.manager_list %>
</div>



designation
table的列是什么?标题是designation中的列,显示一个空白的选择框,请告诉我在索引页中放入什么代码。Naks bro,它起作用了……非常感谢你,bhai..我在4天的时间里被绊倒了that@aaquib欢迎:)