I have a submit form (I'm using simple form) in a bootstrap modal that submits some data and a image, when I don't submit the image (I leave it blank) the form submits the data without problem but when I submit the image it says:
ActionController::UnknownFormat
Form:
<%= 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 %>
Controller:
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
The error is in this line:
respond_to do |format|
Model:
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
You need to tell your form that you'll be uploading binary data, hence you have to make it a multipart form:
<%= simple_form_for resource, html: {multipart: true}, remote: true do |f| %>