1

I have to ask about something that probably no one uses anymore. I want to display flash[:notice] after successfully AJAX action. I'm aware of this and that one and even this gist but none of them fit my example:

  #controller code
  def new
    @registrant = Registrant.new

    respond_to do |format|
      format.html

      if params[:add_patient_to_caregiver]
        format.js { render partial: 'add_patient_to_caregiver' }
      end
    end
  end

#view triggered controller#new action via AJAX
<%= link_to 'Add Patient to Caregiver', patient_to_caregiver_path(add_patient_to_caregiver: true, patient_to_caregiver: registrant.id), method: :get, remote: true %>

I want to have something like format.js { render partial: 'add_patient_to_caregiver', flash[:notice] = 'Patient Added' } to display it in a view. I've come up with a workaround:

_add_patient_to_caregiver.js.erb

$("#add-patient").html("<%= escape_javascript(render :partial => 'registrants/add_patient') %>");
$("#flash-messages").after("<div class='alert alert-success'> Patient Added </div>");

And flash message shows up but there are no close button there. Is there any better way to do so? or how to add close button to that message so that the whole page doesn't reload when it is pressed?

mr_muscle
  • 2,536
  • 18
  • 61

0 Answers0