【问题标题】:Paperclip dosnt save attachments if password has attr_accessor如果密码有 attr_accessor,回形针不会保存附件
【发布时间】:2012-05-17 17:31:51
【问题描述】:

我的项目:

    class User < ActiveRecord::Base
         attr_accessor :password 
         attr_accessible :email,
           :password, 
           :password_confirmation, 
           :first_name, 
           :last_name, 
           :birth_date, 
           :residence, 
           :user_role, 
           :show_email,
           :avatar

         as_attached_file :avatar, 
         :default_url => '/images/system/user_avatars/default/default_avatar.png',
         :url => "/public/images/system/user_avatars/:id_:style.:extension",
         :path => "/public/system/user_avatars/:id_:style.:extension"

         def update_profile(user_id, params) #params has :category and :user params
            @user = User.find(user_id)
            @user.update_attributes(params[:user])
            return params[:category]
         end
    end

所以,我从我的控制器调用此方法并且我没有收到任何错误。回形针显示已保存的附件。数据库已更新,但图像文件未保存。我有一个从头开始的注册,所以我有“attr_accessor:password”

我检查过:

  • 在表单中具有 :multipart => true
  • 在用户模型中有 attr_accessible :avatar

谁能给我一些线索,因为我想不通,为什么回形针不保存文件。

【问题讨论】:

    标签: paperclip attachment


    【解决方案1】:

    同样设置attr_accessible :avatar_file_name,你还需要一个paperclip.rb初始化器:

    require "paperclip"  
    Paperclip.options[:command_path] = "/ImageMagick" 
    

    当然,还要安装 ImageMagick。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多