Angularjs 轨道&x2B;回形针错误!未定义的方法`已附加文件';
我对下一个代码有问题:Angularjs 轨道&x2B;回形针错误!未定义的方法`已附加文件';,angularjs,ruby-on-rails-4,paperclip,Angularjs,Ruby On Rails 4,Paperclip,我对下一个代码有问题: $scope.load_icons = function(file){ filename = file[0].name; filenamearray = filename.split('.'); extencion = filenamearray[filenamearray.length-1]; console.log(user_profiling); if(extencion==='png'||extencion==='gif'||extencio
$scope.load_icons = function(file){
filename = file[0].name;
filenamearray = filename.split('.');
extencion = filenamearray[filenamearray.length-1];
console.log(user_profiling);
if(extencion==='png'||extencion==='gif'||extencion==='jpg'||extencion==='PNG'||extencion==='GIF'||extencion==='JPG'){
$upload.upload({
url: '/user_icons.json',
data: {},
file: file
}).progress(function(evt){
console.log(evt);
}).success(function(data, status, headers, config) {
console.log(data);
}).error(function(data, status, headers, config){
console.log(data);
});
}
}
用户图标.rb
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
class用户图标{:d512=>“512x512>”,:d256=>“256x256”,:d256=>“256x256”,:d128=>“128x128”,:d64=>“64x64”,:d32=>“32x32”},:默认url=>“/marker/:style/missing.png”
验证\u附件\u内容\u类型:图像,:内容\u类型=>/\Aimage\/.\Z/
结束
用户图标控制器.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
class usericoncontroller
我要求加载和调整图像大小为图标(标记),但出现以下错误:
我保存在生成图像的URL数据库中
非常感谢您的帮助我解决了删除模型并正确重新创建的问题
rails g model user_icons user_id:integer url:string image:attachment
我需要声明文件上传的参数,并在我的回形针模型中使用
新手失误;(