ActionController :: UnknownFormat:新用户索引

时间:2019-05-14 12:10:46

标签: ruby-on-rails ruby-on-rails-4 activerecord

请大家帮忙,我能帮忙吗!

我正在尝试在新用户注册时加载索引页面。它应该只加载由他们创建的请求,但是由于他们还没有创建任何请求,因此我在下面收到错误消息。

ActionController :: UnknownFormat在RequestsController#index中 从::-05-开始于2019-05-14 13:06:11 +0100的GET“ /requests.15” 由RequestsController#index处理为   用户负载(0.0ms)选择“用户”。*从“用户”到“用户”。“ id” =? ORDER BY“ users”。“ id” ASC LIMIT 1 [[“ id”,15]] 在12ms内完成406不可接受(ActiveRecord:0.0ms)

ActionController :: UnknownFormat(ActionController :: UnknownFormat):   app / controllers / requests_controller.rb:20:in'index'

这是我的请求索引控制器

class RequestsController < ApplicationController


  def index
    if current_user.landlord?
      @requests = Request.where(house: current_user.houses).order("created_at DESC")
      respond_to do |format|
          format.html
          format.pdf do
            pdf = RequestPdf.new(@request)
            send_data pdf.render, filename: "request_report.pdf",
                                  type: "application/pdf",
                                  disposition: "inline"
          end
        end
    elsif current_user.tenant?
      @requests = Request.where(user_id: current_user).order("created_at DESC")
    else
      @requests = Request.search(params[:search]).order("created_at DESC")
      respond_to do |format|
          format.html
          format.pdf do
            pdf = RequestPdf.new(@request)
            send_data pdf.render, filename: "request_report.pdf",
                                  type: "application/pdf",
                                  disposition: "inline"
          end
        end
    end
  end

提前谢谢!

1 个答案:

答案 0 :(得分:0)

我通过在application_controller中从after_sign_in_path_for中删除“(资源)”来解决此问题。