LoginSignup
0
0

More than 3 years have passed since last update.

js.erbで簡単に非同期通信画像削除

Posted at

はじめ

FontAweSomeで削除アイコンを導入

qiita.rb

<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
xxx.html.erb
  <i class="fa fa-trash-o fa-lg" aria-hidden="true"></i>

image.png

Destroy一例

photos_controller.rb
  def destroy
    @photo = Photo.find(params[:id])
    room = @photo.room

    @photo.destroy
    @photos = Photo.where(room_id: room.id)

    respond_to :js

respond_to :jsのファイル

photos/destroy.js.erb
$('#photos').html("<%= j render 'photos_list' %>")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0