我有一个提交表单(我使用简单的表单)在一个引导模式中提交一些数据和一个图像,当我不提交图像时(我把它留空)表单提交数据没有问题但是当我提交图片时,它说:
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
答案 0 :(得分:1)
您需要告诉您的表单您要上传二进制数据,因此您必须将其设置为多部分形式:
<%= simple_form_for resource, html: {multipart: true}, remote: true do |f| %>