我想为我的用户模型添加多个不同的附件,例如头像和封面照片。我正在使用回形针。
目前可以上传新的头像,但每次我想更新封面照片时我都会收到错误您已登录。。我正在使用设计进行身份验证。
我的模特:
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :firstname, :lastname, :username, :login, :avatar
has_many :wishes
# Virtual attribute for authenticating by either username or email
# This is in addition to a real persisted field like 'username'
attr_accessor :login
validates_uniqueness_of :username
# hide instead of deleting
acts_as_paranoid
# tracking
# include PublicActivity::Model
# tracked owner: Proc.new{ |controller, model| controller.current_user }
# Avatar - Paperclip
has_attached_file :avatar,
:styles => {
:extra_large => "600x600#",
:large => "400x400#",
:medium => "250x250#",
:small => "145x145#",
:tiny => "45x45#",
:icon => "16x16#"
},
:default_url => '/assets/default-user-avatar/:style.jpg'
# Avatar - Paperclip
has_attached_file :cover_photo,
:styles => {
:large => "940x360#",
:extra_large => "1880x720#"
}
# Versions
has_paper_trail
searchable do
text :username, :boost => 5
text :firstname
text :lastname
text :email
end
和表格:
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => ({ :method => :put, :multipart => true })) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :firstname %>
<%= f.input :lastname %>
<%= f.input :username, :wrapper => :prepend do %>
<span class="add-on">@</span>
<%= f.input_field :username %>
<% end %>
<%= f.input :email, :required => true, :autofocus => true %>
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
Avatar:<br/>
<%= f.file_field :avatar %><br/>
Cover Photo:<br/>
<%= f.file_field :cover_photo %><br/>
</div>
<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
希望你们能帮助我!
答案 0 :(得分:0)
您可能想要将cover_photo添加到此行:
attr_accessible :email, :password, :password_confirmation, :remember_me, :firstname, :lastname, :username, :login, :avatar, :cover_photo
...并确保您已在数据库中设置了cover_photo列