1
這是我的模型回形針節能問題
class User < ActiveRecord::Base
has_attached_file :profpic,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "/assets/blonde_user.png"
validates_attachment_content_type :profpic, :content_type => /\Aimage\/.*\Z/
這是我的控制器方法
def uploadpic
p "=========================+++++++++++++++"
p params["user"]["profpic"]
# current_user.profpic = params["user"]["profpic"]
# current_user.profpic_file_name = params["user"]["profpic"]
p "================================="
p params
p params[:user]
current_user.profpic = params["user"]["profpic"]
current_user.save
p "=================================="
redirect_to "/profile"
end
,我的看法是一樣
<div class="picture">
<%= form_for current_user, :url => '/uploadpic', :html => { :multipart => true } do |form| %>
<%= form.file_field :profpic %>
<%= image_tag current_user.profpic.url %>
<% end %>
</div>
在這個表單提交即時得到這樣的錯誤
Paperclip::AdapterRegistry::NoHandlerError in ProfilesController#uploadpic
,並在我的終端,我得到的輸出所有打印之類的語句
Parameters: {"utf8"=>"✓", "authenticity_token"=>"9J2MdO7Ok1sfP13n6R97so1W/HRI0RiDsHJYiOy6B4Q=", "user"=>{"profpic"=>"n.jpg"}}
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
"=========================+++++++++++++++"
"n.jpg"
"================================="
{"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"9J2MdO7Ok1sfP13n6R97so1W/HRI0RiDsHJYiOy6B4Q=", "user"=>{"profpic"=>"n.jpg"}, "controller"=>"profiles", "action"=>"uploadpic"}
{"profpic"=>"n.jpg"}
Completed 500 Internal Server Error in 4ms
幫助。
你的'profpic'參數似乎是一個字符串不是一個正確的類。確保你在表單標記中有'multipart'屬性。 – Eru
這是你的整體觀點還是局部?如果它是局部的,那麼確保任何包裝表單元素具有'multipart:true'作爲html選項。 –
https://github.com/thoughtbot/paperclip#migrations – Nithin