I can't add new directory like services


#1

Hello. I made a services directory and I add a file.
After that I ran jets serve but it was fail.
app/services/seoul_data_api.rb:2:in `class:SeoulDataAPI’: uninitialized constant SeoulDataAPI::HTTParty (NameError)
Is it impossible to add new directory?


#2

Hi @say8425, i’ve been using the /app/services/ directory without any extra configuration


#3

@say8425 Oh, think I see what’s going on here.

The boot process, eager loads the class definitions via autoloading. Autoloading works via a naming convention.

  • seoul_data_api => SeoulDataApi

So SeoulDataApi vs SeoulDataAPI

So you have to rename it to the convention: SeoulDataApi. Think it may be okay to then alias the class. Unsure if there has other effects though. Anyway, here’s an example:

class SeoulDataApi
  # ...
end
SeoulDataAPI = SeoulDataApi

Other thoughts

Jets leverages ActiveSupport::Autoload to handle autoloading. There are Autoloading Gotchas.

Believe that Zeitwerk is being considered as a replacement for ActiveSupport AutoLoad. Will dig into Zeitwerk in time. Hopefully, it helps with some of these gotchas, though unsure if it’ll help with this specific issue.


#4

Ah,!!
This question was so stupid!
I’m sorry for waisting your time that answer my stupid question.
Thank you for kind answer.

By the way, you were so great in RubyKaigi 2019.
And I glad to listen your speaking.


#5

Never mind.
I just call wrong class name.
After I correct the code that calling wrong class name, it perfectly works :ok_hand:


#6

All good! Glad you sorted it out :tada:

Thanks!


#7

Hello

jets serve or console command works perfectly but deploy or build command error again.
But you can solve this issue with adding require 'httparty'in first line.