rails7-wysiwyg-editor icon indicating copy to clipboard operation
rails7-wysiwyg-editor copied to clipboard

Bug in code for blog post (part 1)

Open benjaminwelch opened this issue 8 months ago • 0 comments

First, thanks so much for putting together that blog post. I'm new to Rails and this is exactly what I wanted to learn.

I just wanted to let you know about a bug I ran into while trying to follow along with the code in the post. In this snippet, I think it should be before_action :set_fragment, only: [:update] and def update. I couldn't get things to work until I tried this and then things worked as expected.

I'm new, so perhaps I just missed something but I hope this is helpful. Thanks again.

# app/controllers/fragments_controller.rb

class FragmentsController < ApplicationController
  before_action :set_fragment, only: [:save]

  def save
    @fragment.update(data: params[:data])
    render @fragment
  end

  private

  def set_fragment
    @fragment = Fragment.find(params[:id])
  end
end

benjaminwelch avatar Jun 08 '24 21:06 benjaminwelch