1

我在 rails 3.2 应用程序中有一个管理员命名空间。我想使用https://github.com/edendevelopment/paginate_alphabetically上的 paginate_alphabetically gem 对作者的 postgres 数据库进行分页。

app/controllers/admin 中的控制器(Admin::AuthorsController < AdminController 类)具有:

def index
    @authors = Author.includes(:stories).alphabetical_group(params[:letter])
    respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @authors }
    end
end

app/models 中的 author.rb 模型有: paginate_alphabetically :by => :last_name

app/views/admin/index.html.erb 中的作者视图具有:

<ul class='pagination'>
<%- Author.pagination_letters.each do |letter| -%>
<li><%= link_to(letter, admin_authors_path(:letter => letter)) %></li>
<%- end -%>
</ul>

这似乎正在生成正确的 html,其中:

<ul class='pagination'>
<li><a href="/admin/authors?letter=A">A</a></li> 
...etc.
</ul>

但是点击时链接不会去任何地方。红宝石输出说明如下:

Started GET "/admin/authors?letter=A" for 127.0.0.1 at 2012-08-14 18:18:15 -0400
Processing by Admin::AuthorsController#index as JS
Parameters: {"letter"=>"A", "collection"=>{"list"=>:get}}
Author Load (1.8ms)  SELECT "authors".* FROM "authors" 
Author Load (0.7ms)  SELECT "authors".* FROM "authors" WHERE (LOWER(last_name) LIKE     
'a%') ORDER BY last_name
Story Load (0.6ms)  SELECT "stories".* FROM "stories" INNER JOIN "authors_stories" ON   
"stories"."id" = "authors_stories"."story_id" WHERE "authors_stories"."author_id" = 1
Story Load (0.8ms)  SELECT "stories".* FROM "stories" INNER JOIN "authors_stories" ON "stories"."id" = "authors_stories"."story_id" WHERE "authors_stories"."author_id" = 2
 Story Load (67.1ms)  SELECT "stories".* FROM "stories" INNER JOIN "authors_stories" ON "stories"."id" = "authors_stories"."story_id" WHERE "authors_stories"."author_id" = 3
 Story Load (1.1ms)  SELECT "stories".* FROM "stories" INNER JOIN "authors_stories" ON "stories"."id" = "authors_stories"."story_id" WHERE "authors_stories"."author_id" = 4
 Story Load (1.2ms)  SELECT "stories".* FROM "stories" INNER JOIN "authors_stories" ON "stories"."id" = "authors_stories"."story_id" WHERE "authors_stories"."author_id" = 5
 Rendered admin/authors/_authors.html.erb (131.6ms)
 Rendered admin/authors/index.html.erb within layouts/admin (149.5ms)

在 171 毫秒内完成 200 次 OK(查看次数:96.4 毫秒 | ActiveRecord:73.3 毫秒)

当我实际输入 url localhost:3000/admin/authors?letter=A (或任何其他字母)时,我会得到一个页面,其中包含我想要的内容,一个按字母顺序排列的作者列表,具体取决于字母。它只是不适用于上述链接。

在我的 routes.rb 文件中,我有:

namespace :admin do
  resources :authors
  resources :issues
  resources :stories  
  root :to => 'authors#index
end

想法?

4

0 回答 0