2011-07-26 16 views
0

我想製作一個包含多個表格的頁面。每個表都是可以使用元搜索進行排序的ajax過濾表。這是每個表的排序鏈接。 控制器SomeController:無論如何改變sort_link輸出參數?

def index 
    @search = FirstTable.search(params[:search]) 
    @first_tables = @search.all 

    @search_second_table = SecondTable.search(params[:search_second_table]) 
    @second_tables = @search_second_table.all 

    ... 
end 

查看:

# First table 
sort_link @search, :some_attribute, "Some Attribute" 
#=> www.example.com/some_controller?search[meta_sort]=some_attribute.asc 

# Second table 
sort_link @search_second_table, :some_attribute, "Some Attribute" 
#=> www.example.com/some_controller?search[meta_sort]=some_attribute.asc 

我不知道爲什麼sort_link輸出相同的鏈接或也許我犯了一些錯誤。無論如何改變second_table sort_link的輸出是這樣的。

#=> www.example.com/some_controller?search_second_table[meta_sort]=some_attribute.asc 

Thx for your help。

回答

2

使用link_to解決了我的問題。點擊「Some Attribute」鏈接後,使用jquery將「meta_sort」參數改爲desc,緊接着ajax響應成功返回。 link_to "Some Attribute", :controller => "some_controller", :search_second_table => {:meta_sort => "some_attribute.asc"}