Rails + Paperclip错误! undefined方法`has_attached_file'

时间:2016-01-05 22:57:40

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

我对下一个代码有疑问:

    class UserIcon < ActiveRecord::Base
      has_attached_file :image, :styles => { :d512 => "512x512>", :d256 => "256x256", :d256 => "256x256", :d128 => "128x128", :d64 => "64x64", :d32 => "32x32" }, :default_url => "/marker/:style/missing.png"
      validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
    end

user_icon.rb

class UserIconsController < ApplicationController
  skip_before_filter :verify_authenticity_token

  def create

    @icon = UserIcon.new(params)



    respond_to do |format|
      if @icon.save
        format.html { redirect_to @icon, notice: 'Category was successfully created.' }
        format.json { render action: 'show', status: :created, location: @icon }
      else
        format.html { render action: 'new' }
        format.json { render json: @icon.errors, status: :unprocessable_entity }
      end
    end
  end

  private
    def icons_params
      params.require(:image).permit(:tempfile)
    end


end

user_icons_controller.rb

INNER JOIN Passwords ON Users.userID = Passwords.password

我需要加载图像并将图片大小调整为图标(标记),但我收到以下错误:

Passing base64 encoded strings in URL

我保留在生成的图像的URL数据库中。

非常感谢你的帮助

1 个答案:

答案 0 :(得分:0)

我解决了删除模型并重新正确创建...

rails g model user_icons user_id:integer url:string image:attachment

我需要声明文件上传的param并在我的回形针模型中使用它。

菜鸟错误!! ;(