使用PaperClip在轨道

时间:2015-08-03 13:32:41

标签: ruby-on-rails paperclip

希望你能帮助我解决我目前遇到的问题。

我已设置Paperclip以帮助我上传图片,并在按照说明操作并查看各种指南后,我认为它应该正常工作,但我遇到的问题是它的问题根本不保存图像并显示以下错误。有人能指出学习者朝着正确的方向前进吗?

我已经使用imagemagick通过命令行进行转换而没有任何问题。

更新: 我刚刚查看了我的文件,发现我已按照文档中的要求添加了此文件。我是否需要修改:command_path

更新2 : 我现在已经解决了这个问题,我的解决方案就是答案部分。

Paperclip.options[:command_path] = "/usr/local/bin/"

There was an error processing the thumbnail for f87ef1d19d0a3693810436f1278205e020150803-666-1avrc9e

提取的来源如下:

def create
admin = Admin.new(admin_params)

if admin.save
  redirect_to '/administration'

参数

{"utf8"=>"✓",
 "authenticity_token"=>"lZ9kDGwvbTUTElcOkKPrgpmiX9HlIfVpAXyRROk/jcRdoGJX9/unlBx6SuazNa9BXw0UIJhbmJiSUVin4DrsBg==",
 "admin"=>{"name"=>"fffsfdsa",
 "email"=>"dfsdfsfadsafsd@gmail.com",
 "user_name"=>"hjdfkhasdjhasjfdkh",
 "password"=>"[FILTERED]",
 "password_confirmation"=>"[FILTERED]",
 "avatar"=>#<ActionDispatch::Http::UploadedFile:0x007f9082386cf0 @tempfile=#<Tempfile:/var/folders/t6/jrprg2rd57zch5mkt5cg_5cr0000gn/T/RackMultipart20150803-666-1crp2va.jpg>,
 @original_filename="image_name.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"admin[avatar]\"; filename=\"image_name.jpg\"\r\nContent-Type: image/jpeg\r\n">},
 "commit"=>"Submit"}

型号(admin.rb)

class Admin < ActiveRecord::Base
has_secure_password

has_attached_file :avatar, :styles => {
    :medium => "300x300>",
    :thumb => "50x50#>"},
    :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end

管理控制器

 class AdminController < ApplicationController
def new
end

def create
admin = Admin.new(admin_params)

if admin.save
  redirect_to '/administration'
  flash[:success] = "Admin account created successfully"
else
    flash[:error] = "Unable to create account"
  render 'administration/new_ai_admin'
end
end

private

def admin_params
params.require(:admin).permit(:name, :email, :user_name, :password, :password_confirmation, :avatar)
end
end

2 个答案:

答案 0 :(得分:0)

尝试使用Rails迁移生成器:

rails generate paperclip admin avatar

答案 1 :(得分:0)

我终于设法解决了这个问题,这只是模型中错误类型的情况。这是我的工作管理模型

<强> admin.rb     class Admin&lt;的ActiveRecord :: Base的     has_secure_password

 describe('Employee test', function () {
    beforeEach(() => {
        module('app');
        inject((_$controller_: ng.IControllerService, _$httpBackend_: ng.IHttpBackendService, $http: ng.IHttpService) => {

                httpB = _$httpBackend_;
                http = $http;
                empService = new EmployeeService($http);

                ctrl = $controller("employeeCtrl", { $scope: $scope, empService });
        });
    it("controller constructor",() => {
                empService.testdata = [];
                var ctrlObj = new employeeCtrlClass($scope, empService);
        });
     });