0

そこで、Devise と Paperclip を使用して Ruby on Rails をセットアップしました。erb ファイルを HAML に変換できましたが、新規登録ビューに添付ファイルを入力しようとすると、まだ問題が発生します。Paperclip を使用して移行を行うための適切な手順を実行しました。User テーブルには適切な画像列がすべて含まれていますが、画像入力をページに配置するとランタイム エラーが発生します。

私は Ruby on Rails にかなり慣れていないため (スクリーンキャストやコースを学習して実行するのに約 1 か月しかかかりません)、本当に行き詰まっています。ビルドには時間がかかりましたが、ここでいくつかの答えを得たいと思っていたので、これをもう一度やり直したくありません! ありがとう!

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

ああ、これが私のDBスキーマです:

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

エラー全体を貼り付けていただけますか?エラーのタイトルは?あなたが示したコードとエラーは、それが発生した行にすぎませんが、正確に何がスローされるかはまだわかりません。

PS。ビューについて - 貼り付けが間違っていることを願っています。

于 2013-04-14T20:17:21.560 に答える
0

これにより、ページエラーが修正されました

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