2013-04-14 42 views
0

所以我有一個Ruby on Rails設置Devise和Paperclip。我設法將我的erb文件轉換爲HAML,並且在嘗試在新註冊視圖中添加附件輸入時仍然遇到問題。我採取了適當的步驟來使用Paperclip進行遷移,User表具有所有適當的圖像列,但是當我將圖像輸入放在頁面上時,仍然出現運行時錯誤。RuntimeError - 沒有找到二進制輸入

我對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)上安裝回形針

+0

請嘗試'= f.input:圖像,如:文件,標籤: 「上傳圖片」' –

+0

謝謝納什!我以爲我實際上用作::file屬性,但我想我錯過了那部分。你們真棒! – Lazmeister

回答

0

之前安裝的ImageMagick你能粘貼整個錯誤?什麼是錯誤標題?您顯示的代碼&錯誤只是它發生的行,儘管我們仍然不知道它究竟拋出了什麼。

PS。關於視圖 - 希望這只是錯誤的粘貼,因爲我可以看到它有錯誤的塊。

0

這結束了固定的頁面錯誤

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