[Java] [Rails] Implement image enlargement function using lightbox2

less than 1 minute read

Target

ezgif.com-video-to-gif.gif

Development environment

・Ruby: 2.5.7 Rails: 5.2.4 ・Vagrant: 2.2.7 ・VirtualBox: 6.1 ・OS: macOS Catalina

Premise

Implemented below.

Slim introductionPosting function implementation

Implementation

1. Edit application.html.slim

slim:application.html.slim


doctype html
html
  head
    title
      | Bookers2
    = csrf_meta_tags
    = csp_meta_tag
    = stylesheet_link_tag'application', media:'all','data-turbolinks-track':'reload'
    / Addendum
    link href='https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/css/lightbox.css' rel='stylesheet'
    = javascript_include_tag'application','data-turbolinks-track':'reload'
    / Addendum
    script src='https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/js/lightbox.min.js' type='text/javascript'

2. Edit the image_tag

slim:books/show.html.slim


= link_to @book.image.url,'data-lightbox': @book.image do
  = image_tag @book.image.to_s