Rails 4 with carrierwave 图片上传失败

Rails 4 with carrierwave Image uploaad fails

嗨,当我使用载波在 rails 中上传我的图像时,图像的参数被传递到控制器,但图像没有保存在文件夹中,并且有一个空记录保存在数据库。 我在下面添加了我的表单模型和控制器的代码。

谢谢。

用户模型:

class User < ActiveRecord::Base
  mount_uploader :photo, PhotoUploader
end 

用户控制器:

class UsersController < ApplicationController

def new
  @contact = User.new
end

def save_user
  @contact = User.new
  @contact.first_name = params["first_name"]
  @contact.middle_name = params["middle_name"]
  @contact.photo = params["photo"]
  @contact.save
end 

用户表单:

<%= form_tag('#save_user',:html => {:multipart => true}) do %>
<div class="box-body">
  <div class="row">
    <div class="col-lg-5">
      <div class="input-group">
        <div class="input-group-addon">
          Name <i class="fa fa-user"></i>
        </div>
        <%= text_field_tag "first_name",@contact.first_name,class:'form-control',placeholder:'First Name',:autocomplete => :off%>
      </div>
    </div>
    <div class="col-lg-3">
      <%= text_field_tag "middle_name",@contact.middle_name,class:'form-control',placeholder:'Middle Name',:autocomplete => :off%>
    </div>
    <div class="col-lg-4">
      <%= text_field_tag "last_name",@contact.last_name,class:'form-control',placeholder:'Last Name',:autocomplete => :off%>
    </div>
  </div>
  <br />
  <div class="row">
    <div class="col-lg-6">
      <div class="input-group">
        <div class="input-group-addon">
          DOB <i class="fa fa-calendar"></i>
        </div>
        <%= text_field_tag "dob",@apprentice.dob,class:'form-control',:autocomplete => :off%>
      </div>
    </div>
    <div class="col-lg-6">
      <label> Photo </label>
      <%= file_field(:user,:photo) %>
    </div>
  </div>
</div>
<% end %>

问题出在 form_tag 的多部分上,所以我像这样修改了 form_tag 以使其工作

<%= form_tag('#save_user',:multipart => true) do %>