so paperclip,似乎有一種不同的方式來讓它每次我使用它的工作。表單不保存,如果嘗試上傳圖像與回形針
所以目前我嘗試提交表單,但失敗並重新呈現表單(如果表單沒有保存,這是它應該做的)。
這是我的設置到目前爲止
的Gemfile
gem "paperclip", "~> 3.0"
控制器
def new
@post = Post.new
end
def create
@user = current_user
@post = @user.posts.new(params[:post])
if @post.save
redirect_to root_path, :notice => 'Post Successfully Created'
else
render :action => 'new'
end
end
郵政型號
class Post < ActiveRecord::Base
belongs_to :category
belongs_to :user
attr_accessible :comments, :title, :category_id, :user_id, :photo
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
形式
<%= form_for @post, :class => 'post-form', :html => { :multipart => true } do |f| %>
<%= f.label :title, "Title", :class => 'title_label' %>
<%= f.text_field :title %>
<%= f.label :category_id, "Choose Category", :class => 'title_label' %>
<%= f.collection_select(:category_id, Category.all, :id, :name, :prompt => "Please Select a Category") %>
<%= f.label :comments, "Comments", :class => 'title_label' %>
<%= f.text_area :comments %><br>
<%= f.file_field :photo %>
<%= f.submit 'Submit', :class => 'btn' %>
<% end %>
我的遷移添加照片是成功的,因爲我的架構看起來像這樣
create_table "posts", :force => true do |t|
t.string "title"
t.text "comments"
t.integer "category_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "photo_file_name"
t.string "photo_content_type"
t.integer "photo_file_size"
t.datetime "photo_updated_at"
末
任何人都可以看到原因,如預期,這是不工作?
編輯
我是否需要安裝ImageMagick的,讓圖像的上傳或者這只是在視圖中呈現的圖像?
確定,所以從我已經開始嘗試和調試,並把這個在我看來
<%= @post.errors.full_messages %>
的意見,我得到這個返回
["Photo C:/Users/RICHAR~1/AppData/Local/Temp/bitman20130724-5600-agvtgn.png is not recognized by the 'identify' command.", "Photo C:/Users/RICHAR~1/AppData/Local/Temp/bitman20130724-5600-agvtgn.png is not recognized by the 'identify' command."]
任何想法?
感謝
你使用Rails 3.x版本嗎?嘗試打印表單錯誤:debug @ post.errors – Johny
這是否在我的控制器?在創造行動? – Richlewis
你可以在瀏覽器中使用它,'<%= @ post.errors%>'來查看它。 – rmagnum2002