David Williams wrote in post #1182748:
> Walter Davis wrote in post #1182744:
>> # views/posts/modal.html.erb
>>
>> # routes.rb
>>
>> resources :posts do
>> member do
>> get :modal
>> end
>> end
>
> I tried this method, but it went back to the default one image showing
> problem that I had earlier. I will see if I can find a way around it.
The screen dims, but the modal itself doesn't show. I wrote it exactly
the same way you put it.
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<i><%= image_tag(@post.user.avatar_url(:thumb), class:
'round-image-50') %></i>
<h4 class="modal-title" id="myModalLabel" style="margin-left: 60px;
margin-top: -42px;"><%= post.user.username %></h4>
</div>
<div class="modal-body">
<% if @post.photo.present? %>
<%= image_tag(@post.photo.url(:large), style: 'max-width: 570px;') %>
<% end %>
<div class="modal_post_pos">
<%= sanitize content_with_emoji(@post.body) %>
</div>
</div>
<div class="modal-footer">
<%= render partial: 'comments/template', locals: {commentable: @post,
new_comment: @comment} %>
</div>
In my _posts.html.erb
<% @post_items.each do |post| %>
<%= link_to image_tag(post.photo.url(:medium), style: 'height: 300px;
width: 500px;'), modal_post_path(post), data: {:toggle => 'modal',
:target => '#reusable_modal'}, lazy: true %>
<div id="post-modal" class="modal fade"></div>
<!-- Modal -->
<div class="modal fade" id="reusable_modal" tabindex="-1"
role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
</div>
</div>
</div>
<% end %>
<script>
$(document).on('page:change', function () {
$(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"));
});
});
</script>
posts_controller.rb
def show
@post = Post.find(params[:id])
@new_comment = Comment.build_from(@post,
current_user.id, "")
respond_to do |format|
format.html
format.js { render layout: false , template: 'posts/modal' }
format.json {render json: @post }
end
end
def modal
render layout: false
end