سؤال

This is my model

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/ 

This is my controller method

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

and my view is like

<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>

on this form submission im getting an error like

Paperclip::AdapterRegistry::NoHandlerError in ProfilesController#uploadpic

and in my terminal i get outputs for all print statements like

 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

help.

هل كانت مفيدة؟

المحلول

You should change GET to POST. GET comes commonly in form_for tags. When it is changed to POST, it will work.

    <%= form_for current_user, :url => '/uploadpic', :html => { :multipart => true, :method => 'POST' } do |form| %>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top