Tôi khá mới với ruby, đến từ một nền tảng php, nhưng một cái gì đó không phải là nhấp với tôi.Ruby namespacing
Vì vậy, chúng ta hãy nói rằng tôi có một Ruby on ứng dụng Rails và tôi versioning API của tôi như vậy:
app
|_controllers
|_api
| |_v1
| | |_application_controller.rb
| | |_user_controller.rb
| |_application_controller.rb
|_application_controller.rb
Với cấu trúc lớp với
# Versioned API V1 app controller
module Api
module V1
class ApplicationController
end
end
end
# Versioned API app controller
module Api
class ApplicationController
end
end
# Root app controller
class ApplicationController
end
#The code in question
module Api
module V1
class UserController < ApplicationController
end
end
end
Vì vậy, câu hỏi là, làm ruby tìm kiếm Api::V1::ApplicationController
, Api::ApplicationController
hoặc ApllicationController
để mở rộng?
Có phải < ApplicationController
tìm kiếm không gian tên riêng của nó trừ khi tôi chỉ định Api::ApplicationController
? Nếu có, làm cách nào để chỉ định thư mục gốc?
Cảm ơn bạn, điều này đã xóa bỏ sự nhầm lẫn tôi đã có. – GingerTech
mát mẻ :) khó hiểu nhất là khi bạn gặp phải các vấn đề như mô tả trong sidenotes của tôi – apneadiving
thú vị, tôi nghĩ rằng sidenote của bạn xóa vấn đề tôi đã có [ở đây] (http://stackoverflow.com/questions/29849501/object -const-get-and-rails-cắt-off-cha-đun-tên) – dax