2011-11-05 58 views
1

我想根據用戶的Profile信息搜索並返回用戶的索引。在文檔中提到了嵌套屬性,但由於我是初學者,我不確定如何使用助手來完成我想要的功能。在Rails 3應用程序中使用Ransack的Ransack搜索表單的應用程序

ransack docs提出以下建議:

users_controller.rb

def index 
    @q = User.search(params[:q]) 
    @users = @q.result(:distinct => true) 
end 

def search 
    index 
    render :index 
end 

routes.rb

resources :users do 
    collection do 
    match 'search' => 'users#search', :via => [:get, :post], :as => :search 
    end 
end 

app/views/users/index.html.erb

<%= search_form_for @q, :url => search_users_path, 
        :html => {:method => :post} do |f| %> 
<% end %> 

在窗體我已經嘗試通過使用輪廓編織:

<%= current_user.profile.high_school %> 
<%= f.text_field :profile_high_school_cont %> 

這樣做是不行的,但是。當我搜索屬於至少一個用戶個人資料的字段時,結果不會顯示任何內容。

回答

2

其實,這是行不通的。我有一個f.check_box這是搞砸了。