I have a two forms inside my edit action, one is to update an item inside the item.rb model(which works fine)... and the other one is to create an image in a attachment.rb model. The problem is that it creates a row inside the db images with null values and does not save the actually image along with the correct values.
items_contoller.rb
def edit
#attachment = Attachment.new
end
this is the form for the image create:
<%= form_for #attachment, url: create_attachment_path(#attachment), :html => {:id => "form", :multipart => true }, method: :post do |form| %>
<% if #attachment.errors.any? %>
<div class="centerList">
<div id="error_explanation">
<h2><%= pluralize(item.errors.count, "error") %> <%= t 'store_item_edit_4' %></h2>
<% #attachment.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</div>
</div>
<% end %>
<%= hidden_field_tag :item_id, value: #item.id %>
<div class="form-group">
<div class="text-center">
<label class="btn btn-primary"><%= t 'store_item_edit_5' %><span style="display:none;">
<%= form.file_field :image, multiple: true, id: "uploads" %></span></label>
<%= form.submit '', :style => "display: none;" %>
<% end %>
this is the route:
post "attachments/create"=> "attachments#create", :as => :create_attachment
attachments_controller.rb
def create
#attachment = Attachment.new(attachment_params)
respond_to do |format|
if #attachment.save
format.html { redirect_back fallback_location: root_path, notice: 'Image was successfully uploaded.' }
format.json { render :show, status: :created, location: #attachment }
else
format.html { render :new }
format.json { render json: #attachment.errors, status: :unprocessable_entity }
end
end
end
def attachment_params
params.require(:attachment).permit(:item_id, :account_id, :image)
end
and this is what I get inside the console... at some point as you can see I get a Unpermitted parameter: :image:
started POST "/attachments/create" for 127.0.0.1 at 2018-03-14 17:20:23 +0200
Processing by AttachmentsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"6kgGVoUf2tlM2YdxZis6xavw//zC4azttYi4FFshgw4swiFUIOfb58hCtZxf0If2ihOXz3SCETQSnci6l1IFIA==", "item_id"=>"{:value=>44}", "attachment"=>{"image"=>[#<ActionDispatch::Http::UploadedFile:0x007fc6e4acfb18 #tempfile=#<Tempfile:/var/folders/hq/pr4rt14n7s31v3f6292wtjm00000gn/T/RackMultipart20180314-4193-1jrij48.jpg>, #original_filename="image1.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"attachment[image][]\"; filename=\"image1.jpg\"\r\nContent-Type: image/jpeg\r\n">]}}
Store Load (0.5ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = $1 ORDER BY "stores"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Unpermitted parameter: :image
(0.2ms) BEGIN
SQL (0.4ms) INSERT INTO "attachments" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", "2018-03-14 15:20:23.368574"], ["updated_at", "2018-03-14 15:20:23.368574"]]
(1.2ms) COMMIT
Redirected to https://localhost:3000/store/items/edit/44
Completed 302 Found in 8ms (ActiveRecord: 2.3ms)
Any ideas how to fix this:
You should add:
def attachment_params
params.require(:attachment).permit(:item_id, :account_id, image: {})
end
Related
I'm trying to make a frontend mini admin system to reorder the product images stored as an array by Carrierwave multiple upload.
Frontend is working fine.
In my view, I have:
<%= form_for product, url: product_path(product.id), method: :patch do |form| %>
<div class="field">
<%= form.label :images %>
<div class="image-sortable">
<% product.images.each do |image| %>
<div class="image">
<%= hidden_field :product, :images, multiple: true, value: image.cache_name || image.identifier %>
<%= image_tag(image.url, height: 50) %>
<button type="button" class="remove-image">Quitar</button>
</div>
<% end %>
</div>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
Params are being passed correctly
Processing by ProductsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"X0UIytX4V56npfBIrl/fkaUiIgP4BDiJOGpB8tCdAZMeP7kvDXV1z0wsGge4Kch1TJG9Gzhpbtt5hOpQXbMH/Q==", "product"=>{"images"=>["6919-000-6.jpg", "6919-000-2.jpg", "6919-000-3.jpg", "6919-000-4.jpg", "6919-000-5.jpg"]}, "commit"=>"Update Product", "id"=>"1169"}
In the product update, the order of images are not stored, and I'm getting null values appended.
Product Update (0.9ms) UPDATE "products" SET "images" = $1, "updated_at" = $2 WHERE "products"."id" = $3 [["images", "[\"6919-000-2.jpg\",\"6919-000-3.jpg\",\"6919-000-4.jpg\",\"6919-000-5.jpg\",\"6919-000-6.jpg\",null,null,null,null,null]"], ["updated_at", "2023-01-26 21:08:11.373942"], ["id", 1169]]
In my controller, I have the standard update method:
def update
respond_to do |format|
if #product.update(product_params)
format.html { redirect_to #product }
format.json { render :show, status: :ok, location: #product }
else
format.html { render :edit }
format.json { render json: #product.errors, status: :unprocessable_entity }
end
end
end
i am getting an error with the best_in_place gem.
i want to edit my comments inside of the post show action since i render all comments there.
NoMethodError in Posts#show
Showing undefined method `erererer' for #<Comment:0x00007fc0ff1721c8>
comment view that i render in posts show page.
<!--<h3>there are <%#= pluralize(#comments.count, "comment") %></h3> -->
<% #comments.each do |comment| %>
<div class="media mb-5 ">
<% if comment.user.avatar.present? %>
<%= image_tag comment.user.avatar.url, class: 'rounded mr-3 d-flex', width: 42, height: 42%>
<% else %>
<%= random_avatar 42, "d-flex rounded mr-3"%>
<% end %>
<div class="media-body">
<div class="d-flex justify-content-between" />
<h5 class="mt-0"><a><%=link_to comment.user.username, user_path(comment.user) %></a></h5>
<p class="m-0 form-group">created at <%=time_ago_in_words(comment.created_at) %></p>
</div>
<%= best_in_place comment, comment.body, :as => :textarea %>
<% if current_user == comment.user %>
<span style="font-size: 15px;">
<%= link_to '', [comment.post, comment], method: :delete, data: {confirm: "sure?"}, class: ' btn btn-outline-danger btn-sm pull-right fa fa-trash-o' %>
<%= link_to '',edit_post_comment_path(comment.post, comment), class: 'btn btn-outline-warning btn-sm pull-right fa fa-pencil-square-o' %>
</span>
<% end %>
</div>
</div>
</section>
<%end%>
application.js
$(document).ready(function() {
/* Activating Best In Place */
$('.best_in_place').best_in_place();
});
comments_controller.rb
def update
if #comment.update(params[:comment].permit(:body))
format.html { redirect_to post_path(#post) }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { respond_with_bip(#comment) }
end
end
comment.rb
class Comment < ApplicationRecord
belongs_to :post
belongs_to :user
validates :body, presence: true
end
post.rb
class Post < ApplicationRecord
belongs_to :user
has_many :comments, dependent: :destroy
validates :title, presence: true, length: { minimum: 5 }
validates :body, presence: true, length: { minimum: 240 }
post.controller - add post controller code to question
class PostsController < ApplicationController
before_action :find_post, only: %i[destroy edit update comment_owner upvote downvote]
after_action :verify_authorized, only: [:edit, :update, :destroy, :create, :new]
layout '_app_nav'
def index
return redirect_to post_path(params[:post_id]) if params[:post_id]
return redirect_to user_path(params[:user_id]) if params[:user_id]
#post = Post.all.order('created_at DESC')
#posts = Post.all.order('created_at DESC')
#user = User.all
#posts = if params[:search]
else
Post.all.order('created_at DESC')
end
#comments = Comment.all
end
def new
#post = Post.new
end
def create
#post = current_user.posts.build(post_params)
authorize #post
if #post.save!
redirect_to #post
else
render 'new'
end
end
def show
#post = Post.find(params[:id])
#user = #post.user
#comments = Comment.where(post_id: #post).order('created_at DESC').paginate(:page => params[:page], :per_page => 5)
end
def edit
authorize #post
end
def update
authorize #post
if #post.update(post_params)
redirect_to #post, notice: 'updated.'
else
render :edit
end
end
end
def destroy
#post = Post.find(params[:id])
authorize #post
#post.destroy
redirect_to posts_path
end
private
def post_params
params.require(:post).permit(:title, :body, :user_id)
end
def find_post
#post = Post.find(params[:id])
end
UPDATE
This is the entire request that i get when trying to open posts#show
Started GET "/news/2" for 127.0.0.1 at 2018-07-30 03:12:49 +0200
(0.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by PostsController#show as HTML
Parameters: {"id"=>"2"}
Post Load (0.4ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 3], ["LIMIT", 1]]
Rendering posts/show.html.erb within layouts/_app_nav
Rendered comments/_form.html.erb (27.1ms)
Comment Load (0.9ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = 2 ORDER BY created_at DESC LIMIT $1 OFFSET $2 [["LIMIT", 5], ["OFFSET", 0]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 3], ["LIMIT", 1]]
Rendered comments/_comment.html.erb (14.2ms)
Rendered posts/show.html.erb within layouts/_app_nav (442.2ms)
Completed 500 Internal Server Error in 509ms (ActiveRecord: 12.4ms)
ActionView::Template::Error (undefined method `erererer' for #<Comment:0x00007feba5717bc0>):
15:
16: <p class="m-0 form-group">created at <%=time_ago_in_words(comment.created_at) %></p>
17: </div>
18: <%= best_in_place comment, comment.body, :as => :textarea %>
19: <% if current_user == comment.user %>
20: <span style="font-size: 15px;">
21: <%= link_to '', [comment.post, comment], method: :delete, data: {confirm: "sure?"}, class: ' btn btn-outline-danger btn-sm pull-right fa fa-trash-o' %>
app/views/comments/_comment.html.erb:18:in `block in _app_views_comments__comment_html_erb___2232672375721569353_70325032812060'
app/views/comments/_comment.html.erb:5:in `_app_views_comments__comment_html_erb___2232672375721569353_70325032812060'
app/views/posts/show.html.erb:76:in `_app_views_posts_show_html_erb___2994099099531367002_70324990819000'
<%= best_in_place comment, comment.body, :as => :textarea %> should be <%= best_in_place comment, :body, :as => :textarea %>
I am suffering, because I don't get why my form doesn't write data into my database. If I submit the form I get a new line in the database, which only contains "id", "created at" and "updated at". All other parameters are not submitted. In the log file I get a "unpermitted parameters" message. Where can I change this?
I would be very happy for help. Thanks a lot!
Here is the view to the "new institute" page, which contains the form.
<% provide(:title, 'Institut erstellen') %>
<div class="small_jumbotron jumbotron">
<h1>Institut erstellen</h1>
<div class="row">
<div class="Links">
<%= form_for(#institute) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<br>
<%= f.label :Institutsname %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :Professorenanzahl %>
<%= f.number_field :professors, class: 'form-control' %>
<%= f.label "Anzahl wissenschaftlicher Mitarbeiter" %>
<%= f.number_field :employees, class: 'form-control' %>
<%= f.label "Anzahl an Masterarbeiten" %>
<%= f.number_field :master_theses, class: 'form-control' %>
<%= f.label "Anzahl Lehrveranstaltungen" %>
<%= f.number_field :classes, class: 'form-control' %>
<%= f.label "Minimale Bachelorarbeitenzuordnung" %>
<%= f.number_field :min_workload, class: 'form-control' %>
<%= f.label "Überkapazitätsbereitschaft" %>
<%= f.number_field :overload, class: 'form-control' %>
<%= f.label "Aversion gegen Überkapazitäten" %>
<%= f.number_field :overload_aversion, class: 'form-control' %>
<%= f.label "Kapazität" %>
<%= f.number_field :capacity, class: 'form-control' %>
<br>
<%= f.submit "Erstelle das Institut", class: "btn btn-primary" %>
<% end %>
</div>
</div>
</div>
Here is the institutes controller
class InstitutesController < ApplicationController
before_action :set_institute, only: [:show, :edit, :update, :destroy]
# GET /institutes
# GET /institutes.json
def index
#institutes = Institute.all
end
# GET /institutes/1
# GET /institutes/1.json
def show
end
# GET /institutes/new
def new
#institute = Institute.new
end
# GET /institutes/1/edit
def edit
end
# POST /institutes
# POST /institutes.json
def create
#institute = Institute.new(institute_params)
respond_to do |format|
if #institute.save
format.html { redirect_to #institute, notice: 'Das Institut wurde erstellt.'}
format.json { render :show, status: :created, location: #institute }
else
format.html { render :new }
format.json { render json: #institute.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /institutes/1
# PATCH/PUT /institutes/1.json
def update
respond_to do |format|
if #institute.update(institute_params)
format.html { redirect_to #institute, notice: 'Die Institutsdaten wurden aktualisiert.' }
format.json { render :show, status: :ok, location: #institute }
else
format.html { render :edit }
format.json { render json: #institute.errors, status: :unprocessable_entity }
end
end
end
# DELETE /institutes/1
# DELETE /institutes/1.json
def destroy
#institute.destroy
respond_to do |format|
format.html { redirect_to institutes_url, notice: 'Das Institut wurde gelöscht.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_institute
#institute = Institute.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def institute_params
params.permit(:name, :professors, :employees, :master_theses, :classes, :min_workload, :overload, :overload_aversion, :capacity)
end
end
And now a snippet of the log file
Started POST "/institutes" for 127.0.0.1 at 2018-02-18 16:15:02 +0100
Processing by InstitutesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ufyuHL2iXZpQg1ZmfG1pleuY7aL3JIl+eGn36UJeibML8U5R1sOgw8jd6geBB60XchttET2T3I1SndFgGsR2uA==", "institute"=>{"name"=>"wsd", "professors"=>"", "employees"=>"4", "master_theses"=>"", "classes"=>"", "min_workload"=>"", "overload"=>"", "overload_aversion"=>"", "capacity"=>""}, "commit"=>"Erstelle das Institut"}
Unpermitted parameters: :utf8, :authenticity_token, :institute, :commit
[1m[35m (0.5ms)[0m [1m[36mbegin transaction[0m
[1m[35mSQL (0.6ms)[0m [1m[32mINSERT INTO "institutes" ("created_at", "updated_at") VALUES (?, ?)[0m [["created_at", "2018-02-18 15:15:02.619018"], ["updated_at", "2018-02-18 15:15:02.619018"]]
[1m[35m (17.0ms)[0m [1m[36mcommit transaction[0m
Redirected to http://localhost:3000/institutes/12
Completed 302 Found in 30ms (ActiveRecord: 18.1ms)
You're not using strong_params correctly. Should be like this:
def institute_params
params.require(:institute).permit(:name, :professors, ...)
# ^^^^^^^^^^^^^^^^^^^^
end
I have a partial named _form.html.erb in my alerts/views/ folder. I render that partial from the show page in my agencies/views/ folder.
Everything renders properly, and the partial does create a new alert, but the alert is completely empty.
alerts_controller create method
def create
#alert = Alert.new(body: params[:body],
severity: params[:severity],
agency_id: #current_member.id)
respond_to do |format|
if #alert.save
format.html { redirect_to #alert.agency, notice: 'Alert was successfully created.' }
format.json { render :show, status: :created, location: #alert}
else
format.html { render :new }
format.json { render json: #alert.errors, status: :unprocessable_entity }
end
end
end
_form.html.erb
<%= form_for(Alert.new) do |f| %>
<div class="input-group">
<div class="field">
<%= f.label :body %><br>
<%= f.text_field :body %>
</div>
<div class="field">
<%= f.label :severity %><br>
<%= f.number_field :severity %>
</div>
<div class="action">
<%= f.submit %>
</div>
</div>
<% end %>
There are no errors, except that the alert created is completely empty. The body, severity, and agency_id variables are all nil.
I have tried replacing the line
<%= form_for(Alert.new) do |f| %>
with this:
<%= form_for(#alert) do |f| %>
and adding this line:
#alert = Alert.new
to the show method in the agency controller.
But the same thing happens either way. What am I doing wrong?
EDIT
This is the log starting when I hit submit, and ending before loading the redirect in the alerts.create method.
Started POST "/alerts" for ::1 at 2016-03-31 18:29:43 -0400
Processing by AlertsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"CgpepnYUec9uUoE/Ys6SAkOlzmK+w2q9IN782sXNoXnB3UyuegiS6m+W+mW+nXu4EIL8P8xH6JdigU8FfmzhVw==", "alert"=>{"body"=>"This is the body text", "severity"=>"12345"}, "commit"=>"Create Alert"}
Account Load (0.1ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = ? LIMIT 1 [["id", 7]]
Agency Load (0.1ms) SELECT "agencies".* FROM "agencies" WHERE "agencies"."id" = ? LIMIT 1 [["id", 2]]
(0.1ms) begin transaction
SQL (0.2ms) INSERT INTO "alerts" ("agency_id", "created_at", "updated_at") VALUES (?, ?, ?) [["agency_id", 2], ["created_at", "2016-03-31 22:29:43.014846"], ["updated_at", "2016-03-31 22:29:43.014846"]]
(135.8ms) commit transaction
Agency Load (0.1ms) SELECT "agencies".* FROM "agencies" WHERE "agencies"."id" = ? LIMIT 1 [["id", 2]]
Redirected to http://localhost:3000/agencies/2
Completed 302 Found in 141ms (ActiveRecord: 136.2ms)
When I comment out the alerts.create method and add this line:
render plain: params
This is the output:
{"utf8"=>"✓",
"authenticity_token"=>"3OfteFX41SV/5NxpTcKbP7AKhLm/ZKah+NXVn84e2xwXMP9wWeQ+AH4gpzORkXKF4y225M3gJIu6imZAdb+bMg==",
"alert"=>{"body"=>"This is the body text.", "severity"=>"12345"},
"commit"=>"Create Alert", "controller"=>"alerts", "action"=>"create"}
The root cause is evident from your params debugging. The params hash has an alert key in it. The alert value is a hash of body and severity.
In your controller, you reference params[:body] and params[:severity]. Those should be params[:alert][:body] and params[:alert][:severity].
Was there a reason not to use Rails' strong parameters? You could refactor to something like:
def create
#alert = Alert.new(alert_params.merge(agency_id: #current_member.id)
…
end
…
private
def alert_params
params.require(:alert).permit(:body, :severity)
end
In the create method params supposed to be like this.
Because your params "alert"=>{"body"=>"This is the body text.", "severity"=>"12345"}
def create
#alert = Alert.new(body: params[:alert][:body],
severity: params[:alert][:severity],
agency_id: #current_member.id)
respond_to do |format|
if #alert.save
format.html { redirect_to #alert.agency, notice: 'Alert was successfully created.' }
format.json { render :show, status: :created, location: #alert}
else
format.html { render :new }
format.json { render json: #alert.errors, status: :unprocessable_entity }
end
end
end
I have a polymorphic association with dailyposts & comments in my rails app
Everything works fine in the database, but when I try to add Ajax to the Destroy Action (I used this tutorial http://railscasts.com/episodes/136-jquery-ajax-revised)
....it doesn't work unless I refresh the page. (but my alert works in destroy.js.erb)
I know my error is in destroy.js.erb
New to Rails...Please help :)
This is my code...
ROUTES
resources :dailyposts do
resources :comments
end
CONTROLLERS
##Dailyposts
class DailypostsController < ApplicationController
respond_to :html, :js
def show
#user = User.find_by_username(params[:username])
#dailypost = Dailypost.find_by_id(params[:id])
#commentable = #dailypost
#comments = #commentable.comments.arrange(:order => :created_at)
#comment = Comment.new
end
end
##Comments
class CommentsController < ApplicationController
before_filter :load_commentable
respond_to :html, :js
def create
#comment = #commentable.comments.create(params[:comment])
#comment.user = current_user
if #comment.save
respond_to do |format|
format.html { redirect_to #commentable }
format.js
end
else
redirect_to #commentable, notice: "Comment can't be blank."
end
end
def destroy
#comment = Comment.find(params[:id])
#commentable = #comment.commentable
if #comment.destroy
respond_to do |format|
format.html { redirect_to #commentable }
format.js
end
end
end
private
def load_commentable
resource, id = request.path.split('/')[1, 2]
#commentable = resource.singularize.classify.constantize.find(id)
end
end
VIEWS
Dailypost show.html.erb
<div class="row-fluid">
<div class="span12">
<div>
<%= raw(dailypost_with_links(#dailypost)) %>
</div>
<%= render "comments/form" %>
<div id="comments">
<%= nested_comments #comments %>
</div>
</div>
</div>
_comment.html.erb
<section class="comments">
<div class ="user">
<%= link_to comment.user.username, comment.user %>
<%= comment.content %>
</div>
##Here I am passing remote: true for ajax
<% if current_user?(comment.user) %>
<%= link_to content_tag(:i, "", class: "icon-trash icons"), [#commentable, comment], method: :delete,
data: { confirm: "Are you sure?" },
title: "Delete", remote: true %> |
<% end %>
</section>
destroy.js.erb
##alert is working
alert('ajax works!');
$('#<%= dom_id(#comment) %>').remove();
LOGS
Started DELETE "/dailyposts/11/comments/133" for 127.0.0.1 at 2013-08-04 23:06:31 -0700
Processing by CommentsController#destroy as JS
Parameters: {"dailypost_id"=>"11", "id"=>"133"}
Dailypost Load (0.3ms) SELECT "dailyposts".* FROM "dailyposts" WHERE "dailyposts"."id" = ? ORDER BY dailyposts.created_at DESC LIMIT 1 [["id", "11"]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'sgFH2XeZWEXCcjxiAwgfXg' LIMIT 1
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."id" = ? LIMIT 1 [["id", "133"]]
Dailypost Load (0.1ms) SELECT "dailyposts".* FROM "dailyposts" WHERE "dailyposts"."id" = 11 ORDER BY dailyposts.created_at DESC LIMIT 1
(0.1ms) begin transaction
Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE (comments.ancestry like '133/%' or comments.ancestry = '133')
SQL (0.4ms) DELETE FROM "comments" WHERE "comments"."id" = ? [["id", 133]]
(2.3ms) commit transaction
Rendered comments/destroy.js.erb (0.7ms)
Completed 200 OK in 25ms (Views: 10.3ms | ActiveRecord: 3.9ms)
Try this:
Dailypost show.html.erb
<div id="comments">
<%= render #comments %>
</div>
_comment.html.erb
<div id="<%= dom_id(comment) %>">
<%= comment.content %>
</div>
create.js.erb
$('<%= escape_javascript(render(:partial => #comment))%>').appendTo('#comments').hide().fadeIn();
destroy.js.erb
$('#<%= dom_id(#comment) %>').remove();
The redirect is breaking the response. Try changing it to redirect_to( :back ) unless request.xhr?
The problem is in destroy.js.erb , the second line does not work because there is no id like edit_comment_1 of the format edit_comment_(:id).
In your _comment.html.erb, add an appropriate div with id that is used in your .js.erb
<section class="comment">
<div id="edit_comment_<%= comment.id %>">
<div class ="user">
<%= link_to comment.user.username, comment.user %>
<%= comment.content %>
</div>
<% if current_user?(comment.user) %>
<%= link_to content_tag(:i, "", class: "icon-trash icons"), [#commentable, comment], method: :delete,
data: { confirm: "Are you sure?" },
title: "Delete", remote: true %> |
<% end %>
</div>
</section>