> On Apr 10, 2016, at 1:33 PM, David Williams <li...@ruby-forum.com> wrote:
> 
> It's still not dynamically updating.
> 
>  <!-- Modal -->
>        <div class="modal fade reusable_modal" id="myModal" 
> tabindex="-1" role="dialog" aria-labelledby="myModalLabel" 
> aria-hidden="true">
>          <div class="modal-dialog" role="document">
>            <div class="modal-content">
>              <div class="modal-header">
>                <button type="button" class="close" data-dismiss="modal" 
> aria-label="Close">
>                  <span aria-hidden="true">&times;</span>
>                </button>
>                <%= image_tag(post.user.avatar_url(:thumb), class: 
> 'round-image-50') %>
>                <%= post.user.username %>
>                <h4 class="modal-title" id="myModalLabel"></h4>
>              </div>
>              <div class="modal-body">
>                <%= image_tag(post.photo.url(:large), style: 'max-width: 
> 570px;') %>
>                <%= sanitize content_with_emoji(post.body) %>
>              </div>
>              <div class="modal-footer">
>                <h5>Hello Test</h5>
>              </div>
>            </div>
>          </div>
>        </div>
> 
> 
>  $(document).on('page:change', function(){
>        // shims for the Bootstrap Modal, which is bloody-minded about 
> caching content per modal
>        $(document).on('click', '#reusable_modal 
> [data-dismiss="modal"]',
>            function (e) {
>              $(e.target).removeData('bs.modal');
>              $('#reusable_modal').find('.modal-content').empty();
>            });
>        $(document).on('click', '[data-target="#reusable_modal"]', 
> function(e)
>        {
>          
> $("#reusable_modal").find(".modal-content").load($(this).attr("href"));
>        });
>      });
> 

I think you're missing something, then. Look at this Gist: 
https://gist.github.com/walterdavis/262e8ae9fa0a8447bd7336c6ae518f56

The first snippet is the HTML that your server would return if you requested 
modal-content.html. Imagine if there was another snippet, called 
other-modal-content.html, with different contents.

Then, in your page, you have a link to `modal-content.html` and another to 
`other-modal-content.html`. Note how they are constructed: they have a 
data-target to the same modal (using the id #reusable_modal) and they each 
differ by their href attribute. The href is what jQuery reads and uses to 
populate the body of the modal dialog.

Below those links, you have the outer "frame" of the #reusable_modal itself. 
Note that it is empty, and will be filled by (and emptied again by) the script, 
depending on whether you click on a URL with its data-target, or click on a 
button with data-dismiss within that same element.

I suspect that your only issue here is getting the HTML correct. Having the 
right ID (as noted in the jQuery) in your HTML will mean that the selector 
"finds" the content you wish to change.

In the Rails context, you would obviously not have static HTML for these URLs 
and their snippets, but rather controller methods and routes to them to 
construct your modal contents.

Walter


> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/18f6730352886b04c644a6c82a2a58c4%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/65C48B65-D003-49CE-8AE7-4EC9AAE3B620%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to