设计和回形针,化身不保存。在rails控制台中显示为nil

时间:2015-01-21 03:53:08

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

出于某种原因,我提交时我的图片不会保存。我已经在rails控制台中检查了我的用户,但我得到了这个:

avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil

我已经尝试修复edit.html.erb但它似乎无法正常工作。我已经尝试编辑与此有关的所有内容:avatar tag但它不起作用。

edit.html.erb

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { multipart: true }) do |f| %>
  
<div class="form-group">
    <%= f.label :avatar %>
        <%= f.file_field :avatar, multiple: true, name: "avatar" %>
    </div>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<%= f.label :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 :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>

 <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="actions">
 <%= f.submit "Update" %>
</div>
<% 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 %>        

user.rb

class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
validates :avatar, presence: true
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100#" }, :default_url => "default_avatar.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/

application_controller.rb

class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :authenticate_user!
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:edit) { |u| u.permit({ roles: [] }, :email, :password, :password_confirmation, :first_name, :last_name, :age, :about_me, :gender, :avatar ) }

0 个答案:

没有答案