ruby on rails 3 -一个模型的多个不同附件|回形针



我想有多个不同的附件为我的用户模型,例如头像和封面照片。我用的是回形针。

目前是可以上传一个新的头像,但每次我想更新封面照片,我得到一个错误你已经登录。。我正在使用设计进行身份验证。

我的模型:

# 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 %>

希望你们能帮助我!

您可能需要在这行中添加:cover_photo:

 attr_accessible :email, :password, :password_confirmation, :remember_me, :firstname, :lastname, :username, :login, :avatar, :cover_photo

…同时要确保在数据库中设置了cover_photo列

相关内容

  • 没有找到相关文章

最新更新