0
나는 paper_trail에 대한 간단한 프로젝트를 수행했지만 문제가 발생했습니다.오류 : 메시지가 두 번 보임
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
# GET /products
# GET /products.json
def index
@products = Product.order(:name)
respond_to do |format|
format.html
format.csv { send_data @products.to_csv }
end
end
# GET /products/1
# GET /products/1.json
def show
end
# GET /products/new
def new
@product = Product.new
end
# GET /products/1/edit
def edit
end
# POST /products
# POST /products.json
def create
@product = Product.new(product_params)
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: "Product was successfully created. #{undo_link}" }
format.json { render action: 'show', status: :created, location: @product }
else
format.html { render action: 'new' }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /products/1
# PATCH/PUT /products/1.json
def update
respond_to do |format|
if @product.update(product_params)
format.html { redirect_to product_url, notice: 'Product was successfully updated.' "#{undo_link}" }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
# DELETE /products/1
# DELETE /products/1.json
def destroy
@product.destroy
respond_to do |format|
format.html { redirect_to products_url, notice: "Successfully destroyed product. #{undo_link}" }
format.json { head :no_content }
end
end
def import
Product.import(params[:file])
redirect_to root_url, notice: "Products imported."
end
private
# Use callbacks to share common setup or constraints between actions.
def set_product
@product = Product.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def product_params
params.require(:product).permit(:name, :price)
end
def undo_link
view_context.link_to("undo", revert_version_path(@product.versions.scoped.last), :method => :post)
end
end
여기 레이아웃 파일 :
<!DOCTYPE html>
<html>
<head>
<title>Store</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="container">
<% flash.each do |name, msg|%>
<%= content_tag :div, raw(msg), :id => "flash_#{name}" %>
<% end %>
<%= yield %>
</div>
</body>
</html>
내가 기대 여기
Product was successfully created. undo
Product was successfully created. <a data-method="post" href="/versions/148/revert" rel="nofollow">undo</a>
내 컨트롤러 파일입니다 : 내가 만들거나 업데이트 할 때 완전히 뷰에서 두 개의 메시지 쇼가 있었다 한 번 메시지를 보여 주지만 두 번 보여 주므로 제 실수를 어디에서 말해주십시오.
괜찮 았기 때문에 그 중 하나를 제거 할 수는 있지만 다음과 같이 실행 취소 링크가 표시됩니다. 제품이 성공적으로 생성되었습니다. undo – dailammoc
예, application.html.erb의 일반적인 플래시 메시지가 실제로 원하는 것 대신 원시 메시지를 표시합니다. –