javascript - Rails Ajax call from controller without remote: true -


i have form "establecimientos" (establishments), , when user hits submit button there's validation lead showing modal dialog or redirecting "establecimientos" index page. i've been trying , without remote: true in form having error both times either html or js calls. controller (the form doesn't have remote: true):

def create @establecimiento = establecimiento.new(establecimiento_params)   if !establecimiento.exists?(:nit => @establecimiento.nit)     respond_to |format|       if @establecimiento.save         format.html { redirect_to establecimientos_url, notice: 'el establecimiento se creó exitosamente.'.html_safe }         format.json { render :show, status: :created, location: @establecimiento }              else         format.html { render :new }         format.json { render json: @establecimiento.errors, status: :unprocessable_entity }       end     end   else     respond_to |format|       format.js { render :action => 'create'}       format.html { render :action => 'create', :formats=>[:js]}     end   end   end 

when else block happens :formats=>[:js] doesn't work, content of create.js.erb displayed on new page without rendering plain text (the console shows rendered html). appreciated

form partial

<%= bootstrap_form_for(@establecimiento, label_errors: true,  layout: :horizontal, label_col: "col-sm-3", control_col: "col-sm-7") |f| %> ...content <%= f.form_group %>         <%= f.submit %>     <% end %>       <%= render 'duplicated_modal' %> <% end %> 

create.js.erb

<%@duplicated_establishment = establecimiento.find_by_nit(@establecimiento.nit) %> $('.modal-body').html("ya existe un establecimiento con el mismo nit (<%= j @duplicated_establishment.nit.to_s %>) ubicado en <%= j @duplicated_establishment.direccion_establecimiento  %>, desea crear una nueva sede?"); $('.modal-footer').html("<%= j button_to 'crear nueva sede', new_location_path(@establecimiento), class: "btn btn-primary", "method"=>"post", remote: true%>  <button type='button' class='btn btn-default' data-dismiss='modal'>cancelar</button> ") $('#duplicated_conf_modal').modal("show"); $('#duplicated_conf_modal').on('shown.bs.modal', function () {     $('.first_input').focus() }) 

using remote: true makes calls js there can html calls

if want request read format.js, easiest way hit desired path plus .js @ end. in establecimientos_path + ".js".

i believe can establecimientos_path(format: "js").


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -