Rails中的字母分页4.2

时间:2015-02-26 14:22:37

标签: mysql ruby-on-rails ruby pagination

我目前正在尝试为rails 4.2应用程序创建一个按字母顺序排列的分页栏,而且我正努力让它运行起来。我发现了一些应该这样做的宝石/插件,但它们似乎都与Rails 4不相容(或者我太愚蠢了,无论如何都不能使它们工作)。

如果有人知道任何可以做到这一点的最新宝石,或者可以指出我正确的方向开始,我真的很感激。

编辑:单词在数据库文件中,并通过以下代码按字母顺序提取和排序。我想知道如何设置分页(通过信件)。

我要分页的信息是使用以下代码从mysql数据库中提取的字典中的单词列表:

控制器:

class WordsController < ApplicationController
before_action :set_word, only: [:show, :edit, :update, :destroy]

def index
@words = Word.all
end

def show
end

private
 def set_word
  @word = Word.find(params[:id])
 end

def word_params
  params.require(:word).permit(:word, :wordtype, :description)
end
end

查看:

<p id="notice"><%= notice %></p>

<h1>Listing Words</h1>

<table>
  <thead>
    <tr>
      <th>Word</th>
      <th>Wordtype</th>
      <th>Description</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% @words.each do |word| %>
      <tr>
        <td><%= word.word %></td>
        <td><%= word.wordtype %></td>
        <td><%= word.description %></td>
        <td><%= link_to 'Show', word %></td>
      </tr>
    <% end %>
  </tbody>
</table>

0 个答案:

没有答案