Rails プロジェクトの一部を lib ディレクトリに抽出しようとしていますが、ファイルを正しくリンクする方法がわかりません。私のディレクトリ構造は次のようになります。
lib/
eventable/
calendar.rb
helpers.rb
# Rest of rails directories/files
のイベント可能なディレクトリが必要ですconfig/application.rb
:
config.autoload_paths += %W(#{config.root}/lib #{config.root}/lib/eventable)
私のヘルパーとカレンダーの rb ファイル:
# helpers.rb
module Eventable
module Helpers
def calendar_for...
Calendar.new...
end
end
end
# calendar.rb
module Eventable
class Calendar
# methods defined here
end
end
次に、Eventable::Helpers モジュールを通常の Rails ヘルパーに混ぜてcalendar_for
、ビューで使用できるようにします。
ActionView::Base.send :include, Eventable::Helpers
この最後のステップはうまくいくようです。ただし、このヘルパーを使用しているビューに移動すると、次のようになります。
uninitialized constant Eventable::Helpers::Calendar
Eventable::Calendar.new
代わりにアクセスしようとするようにヘルパーを変更すると、次のようになります。
uninitialized constant Eventable::Calendar
これらすべてを 1 つのファイルにまとめたところ、すべてが完全に機能しました。では、これらのファイルを正しくリンクするにはどうすればよいでしょうか?