我刚刚将Ransack添加到我的小票系统网站。
我的ticket_controller
def index
@q = Ticket.search(params[:q])
@tickets = @q.result(distinct: true)
@tickets = Ticket.all
end
我的门票索引视图
<%= search_form_for @q do |f| %>
<%= f.label :body_cont, "Ticket Title" %>
<%= f.text_field :body_cont %>
<%= f.submit %>
<% end %>
我想搜索我的票证正文是否包含搜索值。
在搜索表单后,我有一个显示所有门票的表
这是该表的一部分
<% @tickets.each do |ticket| %>
<tr>
<td><%= ticket.id %></td>
<td><%= link_to ticket.title, ticket_path(ticket) %></td>
<td><%= ticket.body %></td>
<td><%= ticket.created_at %></td>
<td><%= time_ago_in_words(ticket.updated_at) %></td>
当我开始搜索时(例如使用单词&#34; server&#34;)没有任何反应。我没有收到任何错误......没有任何反应......
你知道什么是错的吗?
更新:不知道?
更新2:
当我开始搜索(搜索服务器)时,我在控制台中获得以下输出:
Started GET "/tickets?utf8=%E2%9C%93&q%5Btitle_cont%5D=server" for 127.0.0.1 at 2014-03-25 10:41:45 +0100
Processing by TicketsController#index as HTML
Parameters: {"utf8"=>"✓", "q"=>{"title_cont"=>"server"}}
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1
(0.0ms) SELECT COUNT(*) FROM "tickets"
(0.0ms) SELECT COUNT(*) FROM "tags"
(0.0ms) SELECT COUNT(*) FROM "comments"
Ticket Load (0.0ms) SELECT "tickets".* FROM "tickets" LIMIT 3 OFFSET 0
CACHE (0.0ms) SELECT COUNT(*) FROM "tickets"
(0.0ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."ticket_id" = ? [["ticket_id", 5]]
Tag Load (0.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."ticket_id" = ? [["ticket_id", 5]]
(0.0ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."ticket_id" = ? [["ticket_id", 6]]
Tag Load (1.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."ticket_id" = ? [["ticket_id", 6]]
(0.0ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."ticket_id" = ? [["ticket_id", 7]]
Tag Load (0.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."ticket_id" = ? [["ticket_id", 7]]
Rendered tickets/index.html.erb within layouts/application (16.3ms)
Completed 200 OK in 31ms (Views: 27.3ms | ActiveRecord: 1.0ms)
更新3:
My Ticket Controller对于def index
看起来像这样 def index
@q = Ticket.search(params[:q])
@ticket = @q.result(distinct: true)
@ticket = Ticket.paginate(:page => params[:page], :per_page => 3)
end
但仍然无法正常工作
更新4:
嘿伙计们,
我发现了错误!这是Ransack和Will_Paginate的结合。我在这里找到了解决方案:https://github.com/activerecord-hackery/ransack/issues/80
感谢您的帮助