这是我的模特
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
帮助。
答案 0 :(得分:2)
您应该将GET更改为POST。 GET通常出现在form_for标签中。当它更改为POST时,它将起作用。
<%= form_for current_user, :url => '/uploadpic', :html => { :multipart => true, :method => 'POST' } do |form| %>