2008-10-28 33 views
1

我使用Searchgasm插件進行搜索和分頁。一切似乎都很好,但頁面鏈接似乎根本不起作用。有沒有人有過Searchgasm之前的這個問題?爲什麼Searchgasm頁面鏈接不起作用?

控制器代碼:

class ArtistsController < ApplicationController 
    # GET /artists 
    # GET /artists.xml 
    def index 
    @search = Artist.new_search 
    @search.per_page = 10 
    @search.page = 2 

    @artists = @search.all 

    respond_to do |format| 
     format.html # index.html.erb 
     format.xml { render :xml => @artists } 
    end 
    end 
end 

查看代碼:

<h1>Listing artists</h1> 

<table> 
    <tr> 
    <th><%= :name %></th> 
    </tr> 

<% for artist in @artists %> 
    <tr> 
    <td><%= link_to artist.name, artist %></td> 
    <td><%= link_to 'Edit', edit_artist_path(artist) %></td> 
    <td><%= link_to 'Destroy', artist, :confirm => 'Are you sure?', :method => :delete %></td> 
    </tr> 
<% end %> 
</table> 

<br /> 

Per page: <%= per_page_select %> 
<br /> 
<br /> 
<% if @search.page_count > 1 %> 
    <div class="pages"><%= page_links :spread => 1 %></div> 
<% end %> 

<%= link_to 'New artist', new_artist_path %> 

回答

3

控制器應該是:

class ArtistsController < ApplicationController 
    # GET /artists 
    # GET /artists.xml 
    def index 
    @search = Artist.new_search(params[:search]) 
    @artists = @search.all 

    respond_to do |format| 
     format.html # index.html.erb 
     format.xml { render :xml => @artists } 
    end 
    end 
end 

線:

@search = Artist.new_search(params[:search]) 

從頁面鏈接抓取參數點擊執行搜索。

相關問題