1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails関係のメモ

Posted at

railsで自作のスクリプトを走らせたいとき

ここが参考になる

rails g tasks hoge
libのtasks以下にhoge.rakeができる

hoge.rake
namespace :hoge do
    desc "hogeの説明を書く。何をするスクリプトか"
    task foo: :environment do
        # ここにやりたい処理を書く
    end
end

自作のクラスとかmoduleとかをこの中で使いたいなら

config/application.rb
config.autoload_paths += %W(#{config.root}/lib)

を書いて、lib以下に置く
ディレクトリ構造とmoduleのネスト構造は一致させるべし
lib/hoge/foo/fuwa_fuwa.rbならmodule Hoge::Foo内でclass FuwaFuwa

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?