Вопрос

I am trying to edit a .rb file with rails.

So I enter:

 $ rails c
 irb(main):001:0> require config/application.rb

and then I get the following error message :

NameEror: undefined local variable or method `config' for main:Object from (irb):1

What am I doing wrong?

Это было полезно?

Решение

You can't edit files with the Rails Console -

The console command lets you interact with your Rails application from the command line. On the underside, rails console uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website

If you're looking to edit your .rb files, I'd look at using a simple editing application such as Notepad ++ to actually edit the file


If you'd like to change the timezone for your app, you should open application.rb with an app like Notepad++ or Dreamweaver, or one of the Ruby IDE's and input this line:

#app/config/application.rb
config.time_zone = 'Central Time (US & Canada)'

Once you've saved the file, restart your Rails server & it should have changed everything for you. Obviously the existing DB entries will be in the old timezone, but that should be okay

Другие советы

I would suggest use pry for this task

gem install pry

After you run pry, you will see a prompt like in ruby console

enter:

edit -r config/application.rb

The editor will be opened (the one set via the EDITOR environment variable) and you can change the file.

When you close the editor, the file will be reloaded, and evaluated right in the console.

Check this out: https://github.com/pry/pry/wiki/Editor-integration

and of course this: http://pryrepl.org/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top