> On Apr 10, 2016, at 11:06 AM, David Williams <li...@ruby-forum.com> wrote:
> 
> Colin Law wrote in post #1182722:
>> On 9 April 2016 at 23:57, David Williams <li...@ruby-forum.com> wrote:
>>> _post.html.erb
>>> 
>>> <%= @post.user.username.capitalize %>
>> 
>> As always it is best to paste the complete error message and tell us
>> which line it refers to.  If it is the line above that is saying
>> undefined method 'user' for nil:NilClass
>> then that means @post is nil.
>> 
>> Colin
> 
> I added the modal before the end block, and then I used the larger image 
> inside of the modal body (instead of the partial posts/post partial). 
> The problem with that approach is that it doesn't work for more than one 
> post. I need the modal button to listen for changes, so that it can open 
> up with new content.

This is a shortcoming of the Bootstrap modal design. In Bootstrap 3 
documentation, they say that being able to reload a modal with different 
content is deprecated, and in Bootstrap 4, they are going to remove the 
possibility (IIRC). The docs mention that if you want to do something like 
this, you should use a client-side framework (I am not a fan of this idea).

Here's what I use in Bootstrap 3 to work around this:

$(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 .modal-content').empty();
  });
  $(document).on('click', '[data-target="#reusable_modal"]', function(e) {
    $("#reusable_modal .modal-content").load($(this).attr("href"));
  });
});

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/2052bd8d2ef35152f8e0707a58c0524e%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/0279F469-40AE-4BCE-BC38-934C3F6E4D55%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to