[英]ActionController::UnknownFormat in controller rspec after rails 4 upgrade
[英]ActionController::UnknownFormat rails 5 controller
編輯#1
查看訂單/顯示,我還沒有添加發票,但是該視圖應該在有或沒有發票鏈接的情況下都可以使用,對嗎?
<section class="pt-4 px-8 animated">
<section class="flex flex-wrap justify-between">
<h3 class="font-normal text-grey-dark mb-4 py-2">Order Information</h3>
<%= render 'layouts/dashboard/account' %>
</section>
<h2 class="text-grey-darkest text-lg no-underline py-4">
Course: <%= @order.course.title %>
</h2>
<section class="py-2">
<p class="text-grey-darkest text-md pb-4"><%= @order.course.description %></p>
<p class="text-grey-darkest text-md">
<b>Course Price:</b>
£<%= @order.course.price %>
</p>
<p class="text-grey-darkest text-md">
<b>Total Price:</b>
£<%= @order.amount %>
</p>
</section>
<section class="text-grey-darkest pt-4">
<h4 class="pb-2">User details</h4>
<p>Name: <%= current_user.full_name %></p>
<p>Email: <%= current_user.email %></p>
</section>
</section>
原始問題
我在控制器中收到ActionController::UnknownFormat
錯誤
class OrdersController < ApplicationController
layout proc { user_signed_in? ? "dashboard" : "application" }
before_action :authenticate_user!
def index
@orders = Order.includes(:course).all
end
def show
@order = Order.find(params[:id])
respond_to do |format|
format.pdf {
send_data @order.receipt.render,
filename: "#{@order.created_at.strftime("%Y-%m-%d")}-aurameir-courses-receipt.pdf",
type: "application/pdf",
disposition: :inline
}
end
end
def create
end
def destroy
end
end
我正在使用使用prawn
的https://github.com/excid3/receipts gem,但是我不確定為什么會出現錯誤。
由於html
格式是Rails
的默認格式,因此您需要在url或鏈接生成器中顯式提供pdf
格式:
localhost:3000/orders/1.pdf
否則,它將嘗試將其加載為localhost:3000/orders/1.html
,但是您尚未在控制器中定義format.html
處理程序。
在應用程序中實現鏈接時,請遵循docs中的示例:
<%= link_to "Download Receipt", charge_path(@charge, format: :pdf) %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.