使用carrierwave在rails中上传图像时的格式未知

时间:2014-11-06 02:47:08

标签: ruby-on-rails carrierwave

我使用gem carrierwave上传图片但是我在控制器的respond_to语句中出错了。

这是我的form.html.erb

 <div class="container-fluid">
<%= form_for @admin_cast,html: {multipart: true,:id=>'create-cast'}, remote: true do |f| %>
  <div class="form-group textfield-width">
    <%= f.label :name %><br>
    <%= f.text_field :name,:class=>'form-control' %>
  </div>
  <div class="form-group select-date">
    <%= f.label :birth_date %><br>
    <%= f.date_select :birth_date,:start_year => 1970,:end_year => 2014, :prompt => { :year => 'Year', :month => 'Month', :day => 'Day'},:html=>{:class => 'form-control'} %>
  </div>
  <div class="form-group">
    <%= f.label :description %><br>
    <%= f.text_area :description,:class=>'form-control',:rows=>'5' %>
  </div>
  <div class="form-group">
    <%= f.label :profile_picture %><br>
    <%= f.file_field :profile_picture,:class=>'form-control' %>
  </div>
  <div class="form-group clearfix">
    <%= f.submit :class=>'btn btn-primary pull-right' %>
  </div>
<% end %>
</div>

//控制器

def update
respond_to do |format|
  if @admin_cast.update(admin_cast_params)
    #format.html { redirect_to @admin_cast, notice: 'Cast was successfully updated.' }
    #format.json { render :show, status: :ok, location: @admin_cast }
    format.js
  else
    #format.html { render :edit }
    #format.json { render json: @admin_cast.errors, status: :unprocessable_entity }
    format.js
  end
end

//模型

class Admin::Cast < ActiveRecord::Base
  has_many :admin_photos, :class=>'Admin::Photo'
  validates :name,:presence => true
  validates :birth_date, :presence=>true
  mount_uploader :profile_picture, Admin::PhotoUploader
end

我真的需要你的帮助。我一直在搜索这一天,我无法得到答案

1 个答案:

答案 0 :(得分:0)

不确定您是否仍在寻找解决方案,但我在远程提交表单时遇到了同样的问题。我通过安装gem https://github.com/JangoSteve/remotipart来解决这个问题。试一试。