我在rails 3.2 app中有一个admin命名空间。我想在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 => :姓氏
作者在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>
但点击时链接不会出现在任何地方。 ruby输出如下:
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)
在171ms完成200 OK(浏览次数:96.4ms | ActiveRecord:73.3ms)
当我实际输入网址localhost:3000 / admin / authors?letter = A(或任何其他字母)时,我会得到一个包含我想要的页面,一个按字母顺序排列的按字母顺序排列的作者列表。它只是不适用于上述链接。
在我的routes.rb文件中,我有:
namespace :admin do
resources :authors
resources :issues
resources :stories
root :to => 'authors#index
end
思想?