未允许的参数错误 - 设计+ Paperclip + Heroku + S3

时间:2016-06-26 04:51:17

标签: ruby-on-rails heroku amazon-s3 devise paperclip

我真的可以通过我使用Devise for users和Paperclip为图片上传构建的应用程序,将配置文件图像正确上传到S3时使用一些帮助。

我的其他模型都通过Hercl到3的Paperclip工作得很好,我唯一无法工作的模型是Devise的用户模型。我已经阅读了100篇关于为设计设置配置的允许参数的不同文章,似乎没有变量可行。我已经阅读了有关此问题的所有Stack Overflow Q& A,似乎没有与我的相关。

我在用户模型中添加了其他属性(配置文件名称,dob等),所有这些属性都正常工作。只有图像不起作用。

我已经在完整的日志文件下面显示了错误消息 - “未经许可的参数:宝丽来。”

Paperclip'image'文件名称为'Polaroid'。

有什么想法?谢谢!

Application Controller.rb

     class ApplicationController < ActionController::Base
      # Prevent CSRF attacks by raising an exception.
      # For APIs, you may want to use :null_session instead.
        protect_from_forgery with: :exception


        before_filter :configure_permitted_parameters, if: :devise_controller?

        protected

        def configure_permitted_parameters
            devise_parameter_sanitizer.for(:account_update).push(:email, :password, :current_password, :password_confirmation, :profile_name, :profile_dob, :profile_zipcode, :profile_country, :profile_timezone, :profile_datejoined, :profile_occupation, :profile_school, :profile_biography, :filter_dateyesno, :filter_distancefrom, :filter_organizerage_min, :filter_organizerage_max, :filter_groupsize_min, :filter_groupsize_max, :profile_gender, :polaroid)
            devise_parameter_sanitizer.for(:sign_up).push(:email, :password, :password_confirmation, :profile_name, :profile_dob, :profile_zipcode, :profile_country, :profile_timezone, :profile_datejoined, :profile_occupation, :profile_school, :profile_biography, :filter_dateyesno, :filter_distancefrom, :filter_organizerage_min, :filter_organizerage_max, :filter_groupsize_min, :filter_groupsize_max, :profile_gender, :polaroid)
        end


    end

用户Controller.rb

class UsersController < ApplicationController
        def index
            @users = User.all
        end 

        def show
            @user = User.find(params[:id])
        end 

        private
            def user_params
                params.require(:user).permit(:email, :password, :current_password, :password_confirmation, :profile_name, :profile_dob, :profile_zipcode, :profile_country, :profile_timezone, :profile_datejoined, :profile_occupation, :profile_school, :profile_biography, :filter_dateyesno, :filter_distancefrom, :filter_organizerage_min, :filter_organizerage_max, :filter_groupsize_min, :filter_groupsize_max, :profile_gender, :polaroid)
            end

    end

Devise Registration

中的Edit.html.erb
<h2>Update Profile Information</h2>

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
  <%= f.error_notification %>

    <div class="field">
      <%= f.label :email %><br />
      <%= f.email_field :email, autofocus: true %>
    </div>

    <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
      <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
    <% end %>

    <% if current_user.polaroid.exists? %>
      <%= image_tag (current_user.polaroid.url(:small)) %><br/>
      <%= f.file_field :polaroid, multiple: true %>
    <% else %>
      <div class="field">
        <%= f.label :profile_photo %>
        <%= f.file_field :polaroid, multiple: true %>
      </div>
    <% end %>

    <div class="field">
      <%= f.label :first_name %><br />
      <%= f.text_field :profile_name, autofocus: true %>
    </div>

    <div class="field">
      <%= f.label :birthday %><br />
      <%= f.date_field :profile_dob, autofocus: true %>
    </div>
    <div class="field">
      <%= f.label :gender %><br />
      <%= f.text_field :profile_gender, autofocus: true %>
    </div>
    <div class="field">
      <%= f.label :zipcode %><br />
      <%= f.text_field :profile_zipcode, autofocus: true %>
    </div>

    <div class="field">
      <%= f.label :country %><br />
      <%= f.text_field :profile_country, autofocus: true %>
    </div>

    <div class="field">
      <%= f.label :timezone %><br />
      <%= f.text_field :profile_timezone, autofocus: true %>
    </div>

    <div class="field">
      <%= f.label :occupation %><br />
      <%= f.text_field :profile_occupation, autofocus: true %>
    </div>

    <div class="field">
      <%= f.label :university_attended %><br />
      <%= f.text_field :profile_school, autofocus: true %>
    </div>

    <div class="field">
      <%= f.label :biography %><br />
      <%= f.text_field :profile_biography, autofocus: true %>
    </div>
    <br />
    <%= f.input :filter_dateyesno, label: "Are you single and looking for dates?", as: :radio_buttons %>
    <br />

    <div class="field">
      <%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
      <%= f.password_field :current_password, autocomplete: "off" %>
    </div>

    <div class="field">
      <%= f.label :new_password %> <i>(leave blank if you don't want to change it)</i><br />
      <%= f.password_field :password, autocomplete: "off" %>
    </div>

    <div class="field">
      <%= f.label :new_password_confirmation %><br />
      <%= f.password_field :password_confirmation, autocomplete: "off" %>
    </div>

    <br />

  <h4>Make sure to type in your password before updating</h4>
  <%= f.button :submit, "Update" %>

<% end %>

<h3>Cancel my account</h3>

<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>

<%= link_to "Back", :back %>

正在运作的其他回形针模型:

        Started POST "/outings" for ::1 at 2016-06-25 20:47:39 -0400
    Processing by OutingsController#create as HTML

      Parameters: {"utf8"=>"✓", "authenticity_token"=>"/eflxdhQ1vPTnTE1YnCOes0k6iggGE64oSI6LDhyRepODp3FZ6FDIaxBVZEZCPge2gHQaHZjjLPhHsUh1IWY6g==", 

    "outing"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fc792c98bf8 
    @tempfile=#<Tempfile:/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/RackMultipart20160625-38562-t3pccn.png>, 
    @original_filename="Beer.png", 
    @content_type="image/png", 
    @headers="Content-Disposition: form-data; name=\"outing[image]\"; 
    filename=\"Beer.png\"\r\nContent-Type: image/png\r\n">, 

    "date_date(1i)"=>"2016", "date_date(2i)"=>"6", "date_date(3i)"=>"28", "date_time(1i)"=>"2016", "date_time(2i)"=>"6", "date_time(3i)"=>"26", "date_time(4i)"=>"00", "date_time(5i)"=>"47", "date_duration"=>"2", "date_title"=>"Beer Garden", "date_category"=>"Drinking", "date_description"=>"Beer Garden", "date_location"=>"New York", "date_city"=>"", "date_state"=>"", "date_zip"=>""}, "commit"=>"Create New Date"}
      User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["id", 20]]
    Command :: file -b --mime '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-40htqc.png'
    Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]' 2>/dev/null
    Command :: identify -format %m '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]'
    Command :: convert '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]' -auto-orient -resize "x600" -crop "600x600+11+0" +repage '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/4331dbefbe38c7e67b6851de8064954e20160625-38562-1ljzx69'
    Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]' 2>/dev/null
    Command :: identify -format %m '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]'
    Command :: convert '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]' -auto-orient -resize "x300" -crop "300x300+5+0" +repage '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/4331dbefbe38c7e67b6851de8064954e20160625-38562-1pw6qi3'
    Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]' 2>/dev/null
    Command :: identify -format %m '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]'
    Command :: convert '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]' -auto-orient -resize "x150" -crop "150x150+2+0" +repage '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/4331dbefbe38c7e67b6851de8064954e20160625-38562-16rm0mr'
    Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]' 2>/dev/null
    Command :: identify -format %m '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]'
    Command :: convert '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-1ep7wo7.png[0]' -auto-orient -resize "x50" -crop "50x50+0+0" +repage '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/4331dbefbe38c7e67b6851de8064954e20160625-38562-ge9nrr'
       (0.3ms)  BEGIN
    Command :: file -b --mime '/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/c6884357e49fd6b1fdede867c96aafb120160625-38562-we9bgq.png'
      SQL (0.5ms)  INSERT INTO "outings" ("date_title", "date_description", "date_duration", "date_category", "date_location", "date_city", "date_state", "image_file_name", "image_content_type", "image_file_size", "image_updated_at", "date_date", "date_time", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) RETURNING "id"  [["date_title", "Beer Garden"], ["date_description", "Beer Garden"], ["date_duration", 2], ["date_category", "Drinking"], ["date_location", "New York"], ["date_city", ""], ["date_state", ""], ["image_file_name", "Beer.png"], ["image_content_type", "image/png"], ["image_file_size", 520764], ["image_updated_at", "2016-06-25 20:47:39.380829"], ["date_date", "2016-06-28"], ["date_time", "2016-06-26 00:47:00.000000"], ["user_id", 20], ["created_at", "2016-06-25 20:47:39.961401"], ["updated_at", "2016-06-25 20:47:39.961401"]]
    [paperclip] saving /outings/images/000/000/017/original/Beer.png
    [paperclip] saving /outings/images/000/000/017/large/Beer.png
    [paperclip] saving /outings/images/000/000/017/medium/Beer.png
    [paperclip] saving /outings/images/000/000/017/small/Beer.png
    [paperclip] saving /outings/images/000/000/017/thumb/Beer.png
       (6.4ms)  COMMIT
    Redirected to http://localhost:3000/outings/17
    Completed 302 Found in 2514ms (ActiveRecord: 7.5ms)

错误讯息 - 未经许可的参数:宝丽来

Started POST "/users" for ::1 at 2016-06-25 20:43:38 -0400
    Processing by Devise::RegistrationsController#create as HTML

      Parameters: {"utf8"=>"✓", "authenticity_token"=>"tNW/ks6w12sLo3T8RBaZhQMBbRyddmdEh6K386BGfwoHPMeScUFCuXR/EFg/bu/hFCRXXMsNpU/Hnkj+TLGiCg==", "user"=>{"email"=>"testjun25v3@testing.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", 

    "polaroid"=>#<ActionDispatch::Http::UploadedFile:0x007fc78f08bf48 @tempfile=#<Tempfile:/var/folders/00/cvfs5p4964q5q3lq115svtf00000gn/T/RackMultipart20160625-38562-1obgcrh.png>, @original_filename="jazz.png", 
    @content_type="image/png", 
    @headers="Content-Disposition: form-data; name=\"user[polaroid]\"; 
    filename=\"jazz.png\"\r\nContent-Type: image/png\r\n">, 

    "profile_name"=>"Jazz Man", "profile_dob"=>"", "profile_gender"=>"", "profile_zipcode"=>"", "profile_country"=>"", "profile_timezone"=>"", "profile_occupation"=>"", "profile_school"=>"", "profile_biography"=>"Jazz Lover"}, "commit"=>"Sign up"}

    Unpermitted parameter: polaroid

       (0.2ms)  BEGIN
      User Exists (0.3ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = 'testjun25v3@testing.com' LIMIT 1
      SQL (0.4ms)  INSERT INTO "users" ("email", "encrypted_password", "profile_name", "profile_gender", "profile_country", "profile_timezone", "profile_occupation", "profile_school", "profile_biography", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id"  [["email", "testjun25v3@testing.com"], ["encrypted_password", "$2a$10$TNIGv9c3GUh8RR.qvMv6eubGd6kgoA6aUeGichYzXWhRYF1QoFvgS"], ["profile_name", "Jazz Man"], ["profile_gender", ""], ["profile_country", ""], ["profile_timezone", ""], ["profile_occupation", ""], ["profile_school", ""], ["profile_biography", "Jazz Lover"], ["created_at", "2016-06-25 20:43:38.367890"], ["updated_at", "2016-06-25 20:43:38.367890"]]
       (1.1ms)  COMMIT
       (0.2ms)  BEGIN
      SQL (0.4ms)  UPDATE "users" SET "last_sign_in_at" = $1, "current_sign_in_at" = $2, "last_sign_in_ip" = $3, "current_sign_in_ip" = $4, "sign_in_count" = $5, "updated_at" = $6 WHERE "users"."id" = $7  [["last_sign_in_at", "2016-06-25 20:43:38.371506"], ["current_sign_in_at", "2016-06-25 20:43:38.371506"], ["last_sign_in_ip", "::1/128"], ["current_sign_in_ip", "::1/128"], ["sign_in_count", 1], ["updated_at", "2016-06-25 20:43:38.372369"], ["id", 20]]
       (0.3ms)  COMMIT
    Redirected to http://localhost:3000/
    Completed 302 Found in 78ms (ActiveRecord: 2.9ms)

用户模型

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_many :clubs
  has_many :outings
  has_many :events
  has_many :activities
  has_many :uploads

  has_attached_file :polaroid, styles: { large: "600x600#", medium: "300x300#", small: "150x150#", thumb: "50x50#" }, default_url: "/images/:style/missing.png"
  validates_attachment_content_type :polaroid, :content_type => ["image/jpg", "image/jpeg", "image/gif", "image/png"]
end

0 个答案:

没有答案