의견 및 첨부 파일을 추가하는 부분이 포함 된 버그 표시/수정 양식이 있습니다.부분 양식의 페이지에서 렌더 유효성 오류 메시지
사용자가 잘못된 첨부 파일 형식이나 빈 메모를 제출하려고하면 유효성 검사에서 오류 [validates :comment, presence: true]
이 발생하고 첨부 파일 [using paperclip gem
]과 유사하게 표시됩니다. 이제는 동일한 버그에 오류 메시지가 표시되기를 바랍니다. 형태. 내 공연 양식에서 GitHub Link
@ 내가 여기에 어떤 도움을
show.html.erb
<%= render partial: 'bug_attachments/bug_form' %>
<%= render partial: 'comments/form' %>
comments/form.html.erb
<% @comment = Comment.new %>
<%= form_for [@bug, @comment] do |f| %>
<%= f.text_area :body, placeholder: "Add a comment" %>
<%= f.submit 'Add Comment'%>
<% end %>
comments_controller.rb
class Bugs::CommentsController < ApplicationController
before_action :authenticate_user!
before_action :set_bug
def create
@comment = @bug.comments.new comment_params
@comment.user = current_user
if @comment.save
redirect_to bug_path(@comment.bug_id), notice: 'Comment added successfully'
else
# Here I am setting @bug = 1 since when the user posts the comments, the @bug becomes nil.
@bug = Bug.find(1)
render 'bugs/show'
# redirect_to @comment, alert: 'Unable to save your comment'
end
end
private
def set_bug
@bug = Bug.find(params[:bug_id])
end
def comment_params
params.require(:comment).permit(:body)
end
end
이에
의 repo 제발입니까?
양식에 ajax를 추가하여이 작업을 수행 할 수 있습니다. 'remote : true' – mrvncaragay
@ Marv-C -이게 어떻게 달성 될 수 있는지 말해 줄 수 있니? – HSD