I have a partial modal window, which I render to the show page:
#myModal.modal.fade
.modal-dialog
.modal-content
.modal-body
%button.close{'aria-hidden' => 'true', 'data-dismiss '=> 'modal', :type => 'button'} ×
= image_tag(@post.image_url.to_s, class: 'modal-image') if @post
show.html.haml:
%p#notice= notice
%p
%b Image:
= link_to image_tag(@post.image_url(:thumb).to_s), '#', class: 'image'
%p
%b Title:
= @post.title
%p
%b Body:
= @post.body
%p
%b User:
= @post.user_id
= link_to 'Edit', edit_post_path(@post)
\|
= link_to 'Back', posts_path
= render 'modal'
The code is called through js:
$(document).ready(function(){
$('.image').click(function(){
$('#myModal').modal('show');
});
});
How do I add a modal window for images on the index page?
index.html.haml:
%h1 Галлерея
- @posts.each_slice(3) do |posts_row|
.row
-posts_row.each do |post|
.col-xs-6.col-md-4
.thumbnail
= link_to image_tag(post.image_url(:thumb).to_s), '#', class: 'image'
.caption
%h3= post.title
%p= post.body
%p
= link_to 'Посмотреть', post
= link_to 'Редактировать', edit_post_path(post)
= link_to 'Удалить', post, :method => :delete, :data => { :confirm => 'Are you sure?' }
= link_to 'New Post', new_post_path