【问题标题】:Why don't Searchgasm page links work? [closed]为什么 Searchgasm 页面链接不起作用? [关闭]
【发布时间】:2008-10-28 02:41:16
【问题描述】:

我正在使用 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 %>

【问题讨论】:

    标签: ruby-on-rails ruby plugins


    【解决方案1】:

    控制器应该是:

    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])
    

    从页面链接中获取参数点击执行搜索。

    【讨论】:

      猜你喜欢
      • 2015-02-02
      • 1970-01-01
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 2022-12-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      相关资源
      最近更新 更多