任何幫助和建議將不勝感激。RANSACK GEM - 搜索協會 - Rails 4
- 我有了很多招聘者(用戶)&
- 招聘人員(用戶)屬於公司
- 還招聘人員屬於一個性別&性別一個公司模型有很多招聘
使用創業板搜索引擎,我試圖顯示在 公司的所有男性招聘人員(用戶),但我不確定在'招聘人員'行動所需的代碼公司控制器 - 無論如何幫助&建議將不勝感激。下面是我的文件:
型號:
user.rb
class User < ActiveRecord::Base
belongs_to :company
belongs_to :category_gender
end
company.rb
class Company < ActiveRecord::Base
has_many :users
end
category_gender
class CategoryGender < ActiveRecord::Base
has_many :users
end
Companies_controller.rb
class CompaniesController < ApplicationController
respond_to :html, :xml, :json
before_action :set_company, only: [:show, :edit, :update, :destroy]
# load_and_authorize_resource
........
def recruiters
@search = Company.search(params[:q])
@companies = @search.result.includes(:users)
@user = current_user
@company = @user.company
end
end
的routes.rb
Rails.application.routes.draw do
resources :companies do
resources :comments, only: [:create, :destroy]
member do
get 'recruiters'
end
end
devise_for :users
resources :users do
resources :comments, only: [:create, :destroy]
resources :adverts
resources :blogs
member do
get 'applications'
get 'applicants'
get 'settings'
get 'dashboard'
get 'management'
end
end
recruiters.html.erb(查看文件):
<%= search_form_for @search, url: recruiters_company_path do |f| %>
<div>
<h3>gender</i></h3>
<ul>
<% CategoryGender.all.each do |gender| %>
<li>
<%= check_box_tag('q[category_gender_name_eq_any][]', gender.name) %>
<%= gender.name %> (<%= gender.users.count %>)
</li>
<% end %>
</ul>
</div>
<button><%= f.submit 'search' %></button>
<% end %>
感謝你洙多! – ARTLoe
我很高興能幫上忙:) –