Carrierwave附件问题

时间:2017-06-26 19:11:19

标签: carrierwave

这里的总菜鸟。我正在尝试构建一个博客应用。 Paperclip不起作用,与兼容性有关。所以我切换到了载波。但是,我仍然无法将任何图像存入我的数据库。

请原谅这个烂摊子 这是我要安装上传者的文章课

    class Article < ActiveRecord::Base

attr_accessor :attachment, :attachment_cache, :remove_attachment

mount_uploader :attachment, AttachmentUploader
serialize :attachments, JSON

has_many :comments
has_many :taggings
has_many :tags, through: :taggings
#has_attached_file :image





end

它是助手的助手

    module ArticlesHelper

def article_params

params.require(:article).permit(:title, :body, :tag_list, :attachment, :attachment_cache, :remove_attachment )

    end

end

这是表格

    <%= form_for(@article, html: {multipart: true}) do |f| %>


<ul>
<% @article.errors.full_messages.each do |error| %>
    <li><%= error %></li>
<%end %>
</ul>

<p>
    <%= f.label :title %><br />
    <%= f.text_field :title %>
</p>
<p>
    <%= f.label :body %><br />
    <%= f.text_area :body %>
</p>

<p>

  <%= f.file_field :attachment, multiple: true %>
  <%= f.label :attachment, "Attach a New Image" %><br />
  <%= attachment_tag (@article.attachment_url) if @article.attachment? %>     
  <%= f.hidden_field :attachment_cache %>

</p>
<p>
    <label>
    <%= f.check_box :remove_attachment %>
    Remove image
    </label>    
</p>

<p>
    <%= f.submit %>
</p>
<p>
    <%= f.label :tag_list %><br />
    <%= f.text_field :tag_list %>
</p>

这是上传者

    class AttachmentUploader < CarrierWave::Uploader::Base


  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end



end

当我发布带有附件的文章时,我会从服务器上获得这种信息:

    Started POST "/articles" for 127.0.0.1 at 2017-06-26 14:56:00 -0400
Processing by ArticlesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"S1qbkO5mz4M0y8k9XyCPujbjOrSG9n6LmyNiTZBNFW8yJQ0j9H52sYYh4KyuMATOpsanO09/T7V9MyNV7sok9g==", "article"=>{"title"=>"yo", "body"=>"reverted on the file stuff", "attachment"=>[#<ActionDispatch::Http::UploadedFile:0x007f8ad5d64f90 @tempfile=#<Tempfile:/tmp/RackMultipart20170626-8487-1c1ts1q.jpg>, @original_filename="friedrich-nietzsche-watercolor-portrait1-fabrizio-cassetta.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"article[attachment][]\"; filename=\"friedrich-nietzsche-watercolor-portrait1-fabrizio-cassetta.jpg\"\r\nContent-Type: image/jpeg\r\n">], "attachment_cache"=>"", "remove_attachment"=>"0", "tag_list"=>""}, "commit"=>"Create Article"}
Unpermitted parameter: attachment
   (0.4ms)  begin transaction
  SQL (0.3ms)  INSERT INTO "articles" ("title", "body", "created_at", "updated_at", "attachment") VALUES (?, ?, ?, ?, ?)  [["title", "yo"], ["body", "reverted on the file stuff"], ["created_at", "2017-06-26 18:56:00.822167"], ["updated_at", "2017-06-26 18:56:00.822167"], ["attachment", nil]]
   (41.2ms)  commit transaction
Redirected to http://localhost:3000/articles/52
Completed 302 Found in 48ms (ActiveRecord: 41.9ms)

有时我可以将参数匹配起来,如果我不尝试添加多个附件并删除这样做的能力,但同样的事情发生在图像上,它从未被处理过。< / p>

提前感谢,正确方向的任何一点都会有所帮助!

0 个答案:

没有答案