Class: Bible270::CommentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Bible270::CommentsController
- Defined in:
- app/controllers/bible270/comments_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/bible270/comments_controller.rb', line 10 def create return unless require_reader! @day = params[:day].to_i head :bad_request and return unless Plan.valid_day?(@day) @comment = current_reader.comments.new(comment_params.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 do render turbo_stream: turbo_stream.replace('new_comment_form', partial: 'bible270/comments/form', locals: { day: @day, comment: @comment }) end format.html { redirect_to day_path(@day), alert: @comment.errors..to_sentence } end end end |
#destroy ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/bible270/comments_controller.rb', line 59 def destroy return unless require_reader! @comment = deletable_comment head :not_found and return unless @comment @day = @comment.day @comment.destroy respond_to do |format| format.turbo_stream format.html { redirect_to day_path(@day) } end end |
#index ⇒ Object
5 6 7 8 |
# File 'app/controllers/bible270/comments_controller.rb', line 5 def index @days_with_reflections = Comment.approved.distinct.pluck(:day).sort @threads = recent_threads end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/bible270/comments_controller.rb', line 35 def update return unless require_reader! @comment = own_comment head :not_found and return unless @comment @day = @comment.day if @comment.update(comment_params.except(:parent_id)) 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 do render turbo_stream: turbo_stream.replace("comment-#{@comment.id}", partial: 'bible270/comments/edit_form', locals: { comment: @comment }) end format.html { redirect_to day_path(@day), alert: @comment.errors..to_sentence } end end end |