Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure if you're still working on this, I had a similar problem and resolved it by doing the following:</p> <p>I'm using the jquery-ui dialog, not bootstrap modal as couldn't make it work. so add the library there should you not have it.</p> <p>in assets/javascripts/application.js i have</p> <pre><code>$(document).ready(function() { var modal=$('#modal'); $('#edit_house_link').click(function(e) { var edit_url = $(this).attr('href'); modal.load(edit_url + ' #content',function(){ modal.dialog("open"); }); }); modal.dialog({ autoOpen: false, title: "Your title", draggable: true, resizable: false, modal: true, width:'auto'}); }); </code></pre> <p>then in my layouts/application.html.erb i have </p> <pre><code>&lt;p id="modal"&gt;&lt;/p&gt; </code></pre> <p>somewhere inside the body of the page, which is the element where we're going to load all the info.</p> <p>in my index view i have the link that handles this, note that my model is called house, so change to whatever yours is called.</p> <pre><code>&lt;%= link_to 'Edit', edit_house_path(house), :remote =&gt; true, :id =&gt; 'edit_house_link' %&gt; </code></pre> <p>As you can see, i'm giving this the edit_house_link id, which I'm referencing in the application.js file.</p> <p>inside the house controller i have:</p> <pre><code>def update @house = House.find(params[:id]) respond_to do |format| if @house.update_attributes(params[:house]) format.js else format.js end end end </code></pre> <p>and then i have three views, one is the edit.html.erb, update.js.erb and _form.html.erb for the views/houses folder.</p> <p>so inside views/houses/update.js.erb i have:</p> <pre><code>&lt;%- if @house.errors.any? %&gt; $('#modal').html('&lt;%= escape_javascript(render('form')) %&gt;'); &lt;%- else %&gt; $('#modal').dialog('close'); $('#modal').remove(); window.location.reload(); &lt;%- end %&gt; </code></pre> <p>this code is to prevent the modal from closing, should there be errors. as you can see, if no errors are present, then it closes the dialog and refreshes the page to display the changes.</p> <p>in the views/houses/edit.html.erb file this is what I have:</p> <pre><code>&lt;div id="content"&gt; &lt;%= render :partial =&gt; 'form' %&gt; &lt;/div&gt; </code></pre> <p>so if you look again at the content id in the application.js file, we're loading this inside the modal.</p> <p>and finally the partial views/houses/_form.html.erb</p> <pre><code>&lt;%= simple_form_for(@house, :html =&gt; { :class =&gt; 'form-vertical' }, :remote =&gt; true) do |f| %&gt; &lt;fieldset&gt; &lt;%= f.input :address %&gt; &lt;%= f.input :postcode %&gt; &lt;%= f.input :city %&gt; &lt;%= f.input :country %&gt; &lt;/fieldset&gt; &lt;div class="form-actions"&gt; &lt;%= f.button :submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>I'm using simple_form, so you can adapt to your needs by having a normal form, but i had to add the :remote => true attribute for it to actually work.</p> <p>hopefully this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload