vinistock/sail

NameError: uninitialized constant Sail::Types when visiting the dashboard

oleg-kiviljov opened this issue · 7 comments

Hello! I have created 1 test setting in sail.yml and loaded it.

  description: Name of the portal
  value: monestro
  cast_type: string
  group: portal_settings

But now when I try to open the dashboard I get the error mentioned in header.

the gem version is 3.0.1, mounted like this:

constraints subdomain: ['backoffice', 'staging-backoffice'] do
    … 
    constraints(Clearance::Constraints::SignedIn.new { |user| user.staff? }) do
     …
        namespace :admin do
  	      mount Sail::Engine => '/sail'
	end
     end
end

Really seems I am not doing anything fancy, so I don't understand why constant resolution for "Sail::Types" does not work

@oleg-kiviljov thanks for the issue. I will try to reproduce the error so that I can fix it.

@oleg-kiviljov I am trying to reproduce the error, but have had no success so far. Would you be able to provide a minimal application that reproduces the error?

Hi, @vinistock, thank you for taking a look at the problem, I'd like to try to fix the issue myself before I try to make a minimal app. Could you please help me out with debugging though? The exception happens here, in Sail::Setting model

def instantiate_caster
      return unless has_attribute?(:cast_type)

      @caster = "Sail::Types::#{cast_type.camelize}"
                .constantize
                .new(self)
    end

for some reason Sail::Types cannot be resolved from inside the Sail::Setting model, I am not familiar with rails engines, could you please point me in some direction where to look forward? In rails console Sail::Types is loaded correctly, problem only occurs when visiting sail settings_controller.

Im using rails 5.1, could that be a problem?

@oleg-kiviljov I'm glad you'd like to contribute! I can sure help debugging. Concerning using Rails 5.1, it shouldn't be a problem.

I am not sure why the module types is not being resolved properly in your application. My initial ideas for debugging would be:

  1. Fork the project to your machine
  2. Point your application to your local version of Sail gem "sail", path: "path/to/sail"
  3. Reproduce the error locally
  4. Try to identify what is going on. If the module Types is not loaded correctly

I actually pushed a commit to use autoload instead of require where possible, so that could potentially fix the issue. Try to reproduce it locally. If the problem persists, throw a byebug right before autoloading the types module and try to find clues as to why it is not being loaded and why it wouldn't be accessible within the Setting model.

Let me know how you're doing so that I can help.

@vinistock, your latest commit fixed the issue, thank you for support and an excellent gem!

@oleg-kiviljov you're welcome! Thanks!