4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/bible270/comments_controller.rb', line 4
def create
return unless require_reader!
@day = params[:day].to_i
head :bad_request and return unless Plan.valid_day?(@day)
@comment = current_reader..new(.merge(day: @day))
@readings = Plan.readings_for(@day)
if @comment.save
respond_to do |format|
format.turbo_stream
format.html { redirect_to day_path(@day, anchor: "comment-#{@comment.id}") }
end
else
respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.replace("new_comment_form", partial: "bible270/comments/form", locals: { day: @day, comment: @comment }) }
format.html { redirect_to day_path(@day), alert: @comment.errors.full_messages.to_sentence }
end
end
end
|