"When clicking the link, javascript we take an id from date attribute, and we add it in the form, and we display a modal window."
How to add id value from javascript in the form?
link:
= link_to _('Report this'), '#', class: 'report', data: { comment_id: comment.id, toggle: 'modal', target: "#report_reasons"}
javascript:
$(function() {
$(".comments").on("click", ".comment a.report", function(e) {
e.preventDefault();
var $this = $(this);
var commentId = $this.data("comment-id");
});
});
form:
= simple_form_for(Report.new, url: report_video_comment_path(video.id, "???"), remote: true) do |f|
routes:
resources :videos, except: [:index] do
resources :comments, only: [:index, :create, :destroy] do
member do
post 'report', to: 'reports#create'
end
end
end
controller:
class ReportsController < ApplicationController
before_filter :authenticate_user!
before_filter :find_comment, only: [:create]
def create
@report = @comment.reports.build(report_params)
@report.user = current_user
@report.save
respond_to do |format|
format.js
end
end
private
def find_comment
@comment = Comment.find(params[:id])
end
def report_params
params.require(:report).permit(:type_report, :message)
end
end
instead of "???", it is necessary to insert data-attr from javascript.
Thanks.