RanSack 复杂的对象关系没有建立......(方法未找到错误)

wit*_*igh 0 associations ruby-on-rails-3.1 ransack

首先是警告。我是一个总的 RoR n00b,但我有编程经验,所以我得到了基本的。我有一个正在构建的应用程序,我需要为其构建一个复杂的搜索引擎。基本布局是指南>> 个人资料>> 指导>> MentorAreas。下面是每个模型的代码,然后是我正在尝试构建的代码。我的问题是我似乎无法找出正确的对象名称来让搜索引擎搜索mentor_areas。

系统设置:

rails -v :: Rails 3.1.1
ruby -v :: ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
RanSack :: ransack (0.5.8) from git://github.com/ernie/ransack.git (at master) 
Run Code Online (Sandbox Code Playgroud)

指导:

class Guide < User
end
Run Code Online (Sandbox Code Playgroud)

用户:(相关内容)

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Virtual attribute for authenticating by either username or email
  # This is in addition to a real persisted field like 'username'
  attr_accessor :login

  # Setup accessible (or protected) attributes for your model
  attr_accessible :login, :username, :email, :password, :password_confirmation, :remember_me, :sex, 
    :location, :role, :first_name, :last_name, :home_town, :profile_attributes

  has_one :profile, :dependent => :destroy
  accepts_nested_attributes_for :profile, :allow_destroy => true

  has_and_belongs_to_many :roles

end
Run Code Online (Sandbox Code Playgroud)

轮廓

class Profile < ActiveRecord::Base
  belongs_to :user
  has_many :mentor_areas, :through => :mentorings
  has_many :mentorings

  accepts_nested_attributes_for :mentor_areas, 
     :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }, :allow_destroy => true

  validates_uniqueness_of  :user_id
end
Run Code Online (Sandbox Code Playgroud)

辅导

class Mentoring < ActiveRecord::Base
   belongs_to :mentor_area
   belongs_to :profile

   validates_uniqueness_of  :profile_id, :scope => :mentor_area_id
end
Run Code Online (Sandbox Code Playgroud)

导师专区

class MentorArea < ActiveRecord::Base
  has_many :profiles, :through => :mentorings
  has_many :mentorings

  validates_uniqueness_of  :mentor_area
end
Run Code Online (Sandbox Code Playgroud)

在我的指南控制器中,我有:

@search_guides = Guide.joins(:roles).where("sex = :sex AND roles.name = :role",{:sex => current_user.sex, :role => 'guide'}).search(params[:search])
@guides_found = @search_guides.all 
Run Code Online (Sandbox Code Playgroud)

在我看来(index.html.erb)我有以下几点:

<%= form_for @search_guides do |f| %>
    <%= f.label :username_cont %>
    <%= f.text_field :username_cont %><br />
    <%= f.label :guides_profiles_mentor_areas_mentor_area_cont %>
    <%= f.text_field :guides_profiles_mentor_areas_mentor_area_cont %><br />
    <%= f.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

我似乎无法弄清楚第二个字段的正确名称应该是什么,以便它搜索某人与该个人资料相关联的mentor_areas。

提前致谢!

更新 RanSack 代码

Ern*_*nie 5

如果我正确阅读您的代码,您需要:

:profile_mentor_areas_mentor_area_cont
Run Code Online (Sandbox Code Playgroud)