アバターやカバー写真など、ユーザー モデルに複数の異なるアタッチメントを用意したいと考えています。ペーパークリップを使っています。
現在、新しいアバターをアップロードすることは可能ですが、カバー写真を更新しようとするたびに、エラーが発生しますYou are already signed in. . 認証にdeviseを使用しています。
私のモデル:
# 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 %>
皆さんが私を助けてくれることを願っています!