0

我在提交一些数据和图像的引导模式中有一个提交表单(我正在使用简单表单),当我不提交图像(我将其留空)时,表单提交数据没有问题但是当我提交时它说的图像:

ActionController::UnknownFormat

形式:

<%= simple_form_for resource, remote: true do |f| %>
  <%= token_tag form_authenticity_token %>
  <%= f.input :design_board_id, as: :hidden %>
  <%= f.input :style, collection: ["Playera", "Blusa", "Short"], prompt: "Selecciona un tipo" %>
  <%= f.input :model %>
  <%= f.input :cost %>
  <%= f.input :description %>
  <%= f.input :image %>
  <%= f.association :production_sequence, prompt: true %>
  <%= f.button :submit, class: "btn-success" %>
<% end %>

控制器:

def create
  @models_definition = ModelsDefinition.new(params.require(:models_definition).permit(permitted_attributes))
  if @models_definition.save
    redirect_to models_definitions_path
  else
    respond_to do |format|
      format.js { render "create" }
    end
  end
end

错误在这一行:

respond_to do |format|

模型:

class ModelsDefinition < ActiveRecord::Base

  belongs_to :production_sequence
  has_many :serigraphies, dependent: :destroy
  has_many :technique_selectors, dependent: :destroy
  belongs_to :accoutrement
  belongs_to :design_board

  mount_uploader :image, ImageUploader

  validates :style, :model, :cost, :production_sequence_id, presence: true

  accepts_nested_attributes_for :technique_selectors, reject_if: :all_blank
  accepts_nested_attributes_for :serigraphies, reject_if: :all_blank

end
4

1 回答 1

2

您需要告诉您的表单您将上传二进制数据,因此您必须将其设为多部分表单:

<%= simple_form_for resource, html: {multipart: true}, remote: true do |f| %>
于 2014-09-08T18:59:42.560 回答