带有Dropzonejs的ActionView :: MissingTemplate

问题描述 投票:0回答:1

我正面临这个错误,当我在dropzone上传图像时(就像表格中的预览器一样),我看不到发生了什么。我有所有的观点......

ActionView::MissingTemplate (Missing template finished_guitars/show, application/show with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in:
  * "/Users/Billy/code/guitar_app/app/views"
):

我有两个型号:

与附件有关系的finished_guitar,我使用回形针上传附件中的图像

我相信我的模特还可以:

attachment.rb

class Attachment < ApplicationRecord
    belongs_to :finished_guitar
    has_attached_file :image, styles: { medium: "300x300>", thumb: "120x120>" }, default_url: "/images/:style/missing.png"
    validates_attachment_content_type :image, :content_type => ["imagse/jpg", "images/jpeg", "images/png"]
end

finished_guitar.rb

class FinishedGuitar < ApplicationRecord
    accepts_nested_attributes_for :attachments, allow_destroy: true
    has_many :attachments
end

我在控制器的某个地方一定是错的:

attachments_controller.rb

class AttachmentsController < ApplicationController

  def create
    @attachment = Attachment.new(attachment_params)
    respond_to do |format|
      if @attachment.save
        format.html { redirect_to @finished_guitar, notice: 'Attachment was successfully created.' }
        format.json { render :show, status: :created, location: @attachment }
      else
        format.html { render :new }
        format.json { render json: @attachment.errors, status: :unprocessable_entity }
      end
    end
  end

  private
    def attachment_params
      params.require(:attachment).permit(:id, :finished_guitar_id, :image)
    end
end

finished_guitars_controller.rb

class FinishedGuitarsController < ApplicationController

    def index
        @finished_guitars = FinishedGuitar.all
    end

    def show
        @finished_guitar = FinishedGuitar.find(params[:id])
        @attachments = @finished_guitar.attachments.all
    end

    def new
        @finished_guitar = FinishedGuitar.new
        @attachments = @finished_guitar.attachments.build
    end


    def create  
        @finished_guitar = FinishedGuitar.new(finished_guitar_params)
    respond_to do |format|
      if @finished_guitar.save
        unless params[:attachments].nil?
            params[:attachments]['image'].each do |a|
                @finished_guitar = @finished_guitar.attachments.create!(:image => a)
            end
        end
        format.html { redirect_to @finished_guitar, notice: 'Guitartest was successfully created.' }
        format.json { render :show, status: :created, location: @finished_guitar }
      else
        format.html { render :new }
        format.json { render json: @finished_guitar.errors, status: :unprocessable_entity }
      end
    end
    end

    def destroy
        @finished_guitar = FinishedGuitar.find(params[:id])
        @finished_guitar.destroy
    end


    private
        def finished_guitar_params
            params.require(:finished_guitar).permit(:title, :description, attachments_attributes: [:finished_guitar_id, :id, :image])
        end
end

编辑:

应用程序/视图/ finished_guitars / _form.html.erb

<div class="content">
    <%= simple_form_for @finished_guitar, html: {multipart: true, id: "my-dropzone", class: "dropzone"} do |f| %>
        <%= f.input :title %>
        <%= f.input :description %>

        <div class="dz-message needsclick">
            <h3>Drop file here</h3> or
            <strong>click</strong> to upload
        </div>
        <div class="fallback">

            <%= simple_fields_for :attachments do |ff| %>
                <%= ff.input_field :image %>
            <% end %>
        </div>
            <%= f.button :submit, class: "btn btn-primary" %>
    <% end %>

</div>
ruby-on-rails paperclip dropzone.js
1个回答
0
投票

该错误告诉您缺少视图。特别是在show.html.erb文件夹中名为views/finished_guitars的文件。你的show.html.erb文件夹中有一个名为views/finished_guitars/的文件吗?

如果你看错误,你可以看到我的意思ActionView::MissingTemplate (Missing template finished_guitars/show。这是一个ActionView错误,错误正是MissingTemplate这意味着一个视图文件丢失,然后它告诉你哪一个finished_guitars/show

我还想确定文件夹名称中是否有拼写错误? app/views/finished_guitasr/_form.html.erb,它说.../finished_guitasr/...。或者你是否在问题中写了这样的内容?

© www.soinside.com 2019 - 2024. All rights reserved.