【发布时间】:2019-01-02 20:28:25
【问题描述】:
我在这里有一个 Rails 应用程序,我正在对它进行搜索。
我已经安装了 Devise,但对于用户索引页面确实没有用处,而是我有一个名为 MemberListController 的控制器,其中包含目录方法和一个链接到它的目录页面。这是我希望我的管理员用户查看会员目录的地方。 (控制器见下文)
MemberListController.rb
class MemberListController < ApplicationController
before_action :authenticate_user!
def directory
@users = User.all
@q = User.ransack(params[:q])
@user = @q.result(distinct: true)
respond_to do |format|
format.html
format.xlsx
end
end
end
我在目录页面中内置了如下搜索表单:
<%= search_form_for @q do |f| %>
<%= f.label :f_name_or_l_name_or_email_or_business_name %>
<%= f.search_field :f_name_or_l_name_or_email_or_business_name %>
<%= f.submit %>
<% end %>
当我从目录页面(我希望显示结果的地方)提交表单时。我收到以下错误:
UsersController#index is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.
我不知道为什么我会使用用户控制器或索引操作,因为一切都是通过目录控制器管理的。
请帮我确定我哪里出了问题。有没有办法像 ransack 一样在用户控制器的外面显示这个?
【问题讨论】:
标签: ruby-on-rails search ransack