Dropzone with Rails表示不保存到数据库

时间:2014-10-08 00:59:59

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

我在将dropzone保存到我的数据库时遇到问题。它显示字段是从日志中进入的,但它没有保存。

%section#profile-editor
      .row
        .small-12.columns
          %h2 Edit Profile
      .row
        .small-12.columns
          .well
            = form_for(current_artist, url: artist_registration_path, method: 'PUT', html: {multipart: true, class: :dropzone, id: 'photo-dropzone'}) do |form|
              .row
                .small-4.columns
                  %input#photo-dropzone{:name => "image", :type => "file"}/
                  = form.hidden_field :image, value: params[:image]
                .small-8.columns
                  .row
                    .small-12.columns
                      = form.label :name
                      = form.text_field :name
                    .small-6.columns
                      = form.label :website_url, "Website URL"
                      = form.text_field :website_url
                    .small-6.columns
                      = form.label :itunes_url, "Itunes URL"
                      = form.text_field :itunes_url
                    .small-6.columns
                      = form.label :video_url, "Youtube Video URL (For Profile)"
                      = form.text_field :video_url
                    .small-6.columns
                      = form.label :email, "Admin Email"
                      = form.text_field :email
                    .small-6.columns
                      = form.label :city, "City"
                      = form.text_field :city
                    .small-6.columns
                      = form.label :state, "State"
                      = form.text_field :state
              .row
                .small-12.columns.pad-top
                  = form.label :about_me, "Content"
                  = form.text_area :about_me, class: "editor"
              = submit_tag "Submit", class: "button button-green"

日志:

        Started PUT "/artists" for 127.0.0.1 at 2014-10-07 17:21:00 -0700
    Processing by Artists::Devise::RegistrationsController#update as HTML
      Parameters: {"utf8"=>"✓", "authenticity_token"=>"Iok5bGQhzPneeZDGbwayqNR2h4LZRjZrVMqY6n3C7II=", "image"=>#<ActionDispatch::Http::UploadedFile:0x007fa5702d0ab0 @tempfile=#<Tempfile:/var/folders/lr/tmtpfc_n0hvcgtb5mhxymbkh0000gn/T/RackMultipart20141007-18936-80n9dr>, @original_filename="uqM07w8.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"image\"; filename=\"uqM07w8.jpg\"\r\nContent-Type: image/jpeg\r\n">, "artist"=>{"image"=>"", "name"=>"", "website_url"=>"", "itunes_url"=>"", "video_url"=>"", "email"=>"aaa@gmail.com", "city"=>"", "state"=>"", "about_me"=>""}, "commit"=>"Submit"}
      Artist Load (0.4ms)  SELECT  "artists".* FROM "artists"  WHERE "artists"."id" = 33  ORDER BY "artists"."id" ASC LIMIT 1
      Artist Load (0.2ms)  SELECT  "artists".* FROM "artists"  WHERE "artists"."id" = $1 LIMIT 1  [["id", 33]]
       (0.1ms)  BEGIN
      SQL (0.3ms)  UPDATE "artists" SET "itunes_url" = $1, "updated_at" = $2 WHERE "artists"."id" = 33  [["itunes_url", ""], ["updated_at", "2014-10-08 00:21:00.192606"]]
       (0.4ms)  COMMIT

我真的迷失在哪里。有些东西设置得不对,我无法弄明白。谢谢你提前。

1 个答案:

答案 0 :(得分:2)

艺术家 param集合中的图片属性(“artist”=&gt; {“image”=&gt;“”})实际上是空白< / strong>,这就是为什么不保存附件的原因。尝试更改此行:

%input#photo-dropzone{:name => "image", :type => "file"}

要:

%input#photo-dropzone{:name => "artist[image]", :type => "file"}

这应该强制图像属性进入参数中的艺术家集合。

如果有帮助,请告诉我。