superclass mismatch error from class in Trailblazer operation when making changes to Rails code while server is running

357 Views Asked by At

I'm using the Trailblazer gem with Rails, and there's a Cell class inside one of my Trailblazer operations that starts throwing a superclass mismatch error whenever I change the code with the server running.

If I start the server and immediately start navigating the site, everything runs fine.

However, if change some code any time after starting the server, and then try to load a page on the site, I get a superclass mismatch error.

2

There are 2 best solutions below

0
neurodynamic On BEST ANSWER

Turns out the name of my operation was not the same as the name of the file I created for the operation. I had recently changed the filename from register.rb to make_reservation.rb, but hadn't changed the operation class name from Register to MakeReservation. When I made the class name change as well, the superclass mismatch error stopped happening.

0
Ziyan Junaideen On

If you are toying with the Trailblazer book with Rails 5-pre you would need to watch out for the change in name spacing. Not having the name spacing properly resulted in a similar error.

Although in Rails 4, models inherit from ActiveRecord::Base in Rails 5 it is form ApplicationRecord.

Your app/concepts/thing/operation.rb in my case app/concepts/listing/operation.rb should be some thing like...

class Listing < ApplicationRecord
  class Create < Trailblazer::Operation
    def process(params)
      @model = Listing.create(params[:listing])
    end
  end
end