0

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

我对 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 机器(10.8)上安装了 ImageMagick

4

2 回答 2

0

这最终修复了页面错误

= f.input :image, as: :file, label: "Upload an image"
于 2013-04-15T03:29:17.843 回答
0

你能粘贴整个错误吗?错误标题是什么?您显示的代码和错误只是它发生的行,尽管我们仍然不知道它到底抛出了什么。

PS。关于视图 - 希望它只是错误的粘贴,因为如我所见,它有错误的意图块。

于 2013-04-14T20:17:21.560 回答