RuntimeError - 找不到二进制文件的输入

时间:2013-04-14 19:04:57

标签: ruby-on-rails devise paperclip

所以我使用Devise和Paperclip设置Ruby on Rails。我设法将我的erb文件转换为HAML,并且当我尝试在新注册视图上放置附件输入时仍然存在问题。我采取了正确的步骤来使用Paperclip进行迁移,User表具有所有正确的图像列,但是当我将图像输入放在页面上时仍然会出现运行时错误。

我是Ruby on Rails的新手(只有大约一个月的学习和做一些截屏和课程)而且我真的被卡住了。我宁愿不再这样做,因为它需要一些时间来构建,但我希望在这里得到一些答案!谢谢!

gem 'rails', '3.2.11'
gem 'jquery-rails'
gem 'devise'
gem 'simple_form'
gem "paperclip", "~> 3.0"
gem "haml"

这是错误:

Extracted source (around line #6):

3:   = f.error_notification
4:   = f.full_error :image_file_size, class: "alert alert-error"
5:   = f.full_error :image_content_type, class: "alert alert-error"
6:   = f.input :image, label: "Upload an image"
7:   = f.input :name, :autofocus => true
8:   = f.input :email
9:   = f.input :password

app/views/devise/registrations/new.html.haml:6:in `block in _app_views_devise_registrations_new_html_haml___1664083891059168154_70305669109760'
app/views/devise/registrations/new.html.haml:2:in `_app_views_devise_registrations_new_html_haml___1664083891059168154_70305669109760'

这是new.html.haml视图:

%h2 Sign up
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: {class: 'form-horizontal'}) do |f|
= f.error_notification
= f.full_error :image_file_size, class: "alert alert-error"
= f.full_error :image_content_type, class: "alert alert-error"
= f.input :image, label: "Upload an image"
= f.input :name, :autofocus => true
= f.input :email
= f.input :password
= f.input :password_confirmation
.form-actions
    = f.submit "Sign up", class: "btn btn-primary"
= render "devise/shared/links"

以下是模型:

class User < ActiveRecord::Base
    devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable

    attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :provider, :uid, :image
    validates :description, presence: true
    validates :user_id, presence: true
    validates_attachment :image, presence: true,
        content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] }, size: { less_than: 2.megabytes }
    has_attached_file :image, styles: { medium: "320x240>"}
end

哦,这是我的数据库架构:

add_index "referrals", ["user_id"], :name => "index_referrals_on_user_id"

create_table "users", :force => true do |t|
    t.string   "email",                                     :default => "", :null => false
    t.string   "encrypted_password",                        :default => "", :null => false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",                             :default => 0
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at",                                                :null => false
    t.datetime "updated_at",                                                :null => false
    t.string   "name"
    t.string   "provider"
    t.string   "uid"
    t.binary   "image",                  :limit => 1048576
    t.string   "image_file_name"
    t.string   "image_content_type"
    t.integer  "image_file_size"
    t.datetime "image_updated_at"
end

    add_index "users", ["email"], :name => "index_users_on_email", :unique => true
    add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true

哦,最后一件事,我在安装回形针之前在我的OSX机器上安装了ImageMagick(10.8)

2 个答案:

答案 0 :(得分:0)

你能粘贴整个错误吗?什么是错误标题?代码&amp;你所显示的错误只是它发生的行,尽管我们仍然不知道究竟是什么引起的。

PS。关于视图 - 希望它只是错误的粘贴,因为正如我所看到的,它有错误的意图阻止。

答案 1 :(得分:0)

最终修复了页面错误

= f.input :image, as: :file, label: "Upload an image"