선착순. 나는 총 RoR n00b이지만 프로그래밍에 대한 경험이 있으므로 기본을 얻습니다. 복잡한 검색 엔진을 구축해야하는 응용 프로그램이 있습니다. 기본 레이아웃은 Guides >> Profiles >> Mentorings >> MentorAreas입니다. 아래는 각각의 모델에 대한 코드와 빌드하고자하는 코드입니다. 내 문제는 내가 검색 엔진을 멘토 _ 영역을 검색 할 수있는 적절한 개체 이름을 알아낼 수없는 것입니다.RanSack 복합 개체 관계가 구축되지 않음 ... (메서드를 찾을 수 없음 오류)
시스템 설정 :
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)
가이드 :
class Guide < User
end
사용자 : (관련 무엇을)
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
프로필
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
,363,210
멘토링
class Mentoring < ActiveRecord::Base
belongs_to :mentor_area
belongs_to :profile
validates_uniqueness_of :profile_id, :scope => :mentor_area_id
end
MentorArea 내 가이드 컨트롤러에서
class MentorArea < ActiveRecord::Base
has_many :profiles, :through => :mentorings
has_many :mentorings
validates_uniqueness_of :mentor_area
end
내가 가진 : 내가
@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
내보기 (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 %>
두 번째 필드에 대해 올바른 이름이 무엇인지 알아낼 수 없으므로 사람이 프로파일과 연관된 멘토 _ 영역에 대해 검색합니다.
미리 감사드립니다.
:profiles_mentorings_mentor_area_mentor_area_contains
기본적으로, 당신은 당신이 당신의 검색 필드에 도착하는 순서대로 하나 하나를 통해 도달해야하는 테이블에 대해 생각할 필요가있다 :
내가 그것을 생각 더듬다 코드
참으로 불행하게도 그 중 하나가 작동하지 않습니다. 내 모델에 뭔가가 제대로 설정되지 않았는지 궁금합니다.나는 또한 meta_search에 대한 rails3.1 대체품으로 여겨지는 ransack을 시도했다. 여전히 사랑이 없다. – witharmshigh