2008-10-28 9 views
1

J'utilise le plugin Searchgasm pour ma recherche et ma pagination. Tout semble fonctionner très bien mais les liens de page ne semblent pas fonctionner du tout. Quelqu'un at-il déjà eu ce problème avec Searchgasm?Pourquoi les liens de la page Searchgasm ne fonctionnent-ils pas?

Code du contrôleur:

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 

Afficher le code:

<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 %> 

Répondre

3

Le contrôleur doit être:

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 

La ligne:

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

Récupère les paramètres du lien de page pour effectuer la recherche.

Questions connexes