Carrierwave上传图片到postgresql表

时间:2014-10-19 00:32:42

标签: ruby-on-rails ruby postgresql carrierwave

我正在尝试为我的表单制作上传个人资料图片选项。我正在使用carrierwave这样做。虽然我可以毫无问题地运行表单,但当我上传并保存更改(我认为)时,我会检查我的postgres数据库列并看到avatar列仍为空。图像尚未保存。

这是我的表格:

<h2>Edit <%= resource_name.to_s.humanize %></h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put , :multipart => true}) do |f| %>
  <%= devise_error_messages! %>

  <div><%= f.label :email %><br />
  <%= f.email_field :email, autofocus: true %></div>

  <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
    <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
  <% end %>

  <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
    <%= f.password_field :password, autocomplete: "off" %></div>

  <div><%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, autocomplete: "off" %></div>

  <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
    <%= f.password_field :current_password, autocomplete: "off" %></div>

  <!-- add profile picture portion -->

  <div><%= f.label :avatar %><br />
    <%= f.file_field :avatar %>


  <div><%= f.submit "Update" %></div>
<% end %>

这是我的模特:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  mount_uploader :avatar, AvatarUploader
end

这是我的上传者:

class AvatarUploader < CarrierWave::Uploader::Base
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end
end

0 个答案:

没有答案