am trying to load a file where i have all my setting into rails console. i want to do it because when i use the console there is too much repetition . thank you
我正在尝试加载一个文件,我将所有设置都放入rails控制台。我想这样做,因为当我使用控制台时,重复次数过多。谢谢
3 个解决方案
#1
9
You can set configs of IRB using .irbrc
file located in your home directory.
您可以使用位于主目录中的.irbrc文件设置IRB的配置。
You can use load
, require
and whatever you want there.
你可以使用load,require和你想要的任何东西。
Adding something like require 'rubygems'
and require 'pp'
will help. Some people customize the file more heavily. See this for example.
添加诸如require'rubygems'和require'pp'之类的东西会有所帮助。有些人更重视自定义文件。例如,见这个。
#2
6
From within Rails console or IRB you can load a file with the require method. For example require foo.rb
will execute all the statements in foo.rb
. You can use relative or absolute paths.
在Rails控制台或IRB中,您可以使用require方法加载文件。例如,require foo.rb将执行foo.rb中的所有语句。您可以使用相对路径或绝对路径。
#3
0
As stated before you can use .irbrc file, take a look here http://github.com/ryanb/dotfiles to see how to separate your rails specific code into a railsrc file.
如前所述,您可以使用.irbrc文件,请查看http://github.com/ryanb/dotfiles,了解如何将rails特定代码分隔为railsrc文件。
#1
9
You can set configs of IRB using .irbrc
file located in your home directory.
您可以使用位于主目录中的.irbrc文件设置IRB的配置。
You can use load
, require
and whatever you want there.
你可以使用load,require和你想要的任何东西。
Adding something like require 'rubygems'
and require 'pp'
will help. Some people customize the file more heavily. See this for example.
添加诸如require'rubygems'和require'pp'之类的东西会有所帮助。有些人更重视自定义文件。例如,见这个。
#2
6
From within Rails console or IRB you can load a file with the require method. For example require foo.rb
will execute all the statements in foo.rb
. You can use relative or absolute paths.
在Rails控制台或IRB中,您可以使用require方法加载文件。例如,require foo.rb将执行foo.rb中的所有语句。您可以使用相对路径或绝对路径。
#3
0
As stated before you can use .irbrc file, take a look here http://github.com/ryanb/dotfiles to see how to separate your rails specific code into a railsrc file.
如前所述,您可以使用.irbrc文件,请查看http://github.com/ryanb/dotfiles,了解如何将rails特定代码分隔为railsrc文件。