0

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?

Litmus
  • 10,558
  • 6
  • 29
  • 44
Mel
  • 27
  • 1
  • 9
  • I don't get it. What exactly (and what for) do you want to do? Why do you want to require config/application.rb? If you run rails console, config/application.rb is already required. – Marek Lipka Nov 12 '13 at 09:24
  • Hello Marek, I need to change a line of code on the file and then want to "activate" this change (I am new to rails) and I was told to do it from the console but it is not working – Mel Nov 12 '13 at 09:27
  • 1
    Rails Console loads your app anyway -- it's only designed to help you run basic commands & processes. I think you're out of context with this – Richard Peck Nov 12 '13 at 09:27
  • @Mel what change do you want to do? – Marek Lipka Nov 12 '13 at 09:28
  • Hi Rich. But then if I make the change under text edit for instance, how to make sure these changes are "activated" if I do this outside of the rails console? – Mel Nov 12 '13 at 09:29
  • You can run `rails s` from the same cmd, which allows you to run your Rails app on your local machine -- this will allow you to see if the app is running as you designed. Alternatively, there are a series of testing gems such as [Capybara](https://github.com/jnicklas/capybara) which can help you :) – Richard Peck Nov 12 '13 at 09:32

2 Answers2

0

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

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • I just need to change the time zone "config.time_zone = 'Central Time (US & Canada)'" so it is simple stuff but I was wondering if I needed to perform this action in a specific ruby environment – Mel Nov 12 '13 at 09:34
  • Thanks for the comment!! Are you trying to change the time zone for the entire app, for the server or for specific users? – Richard Peck Nov 12 '13 at 09:35
  • for the app and for the server! (Ubuntu) I need to change it to UTC – Mel Nov 12 '13 at 09:38
  • 1
    http://stackoverflow.com/questions/6118779/how-to-change-default-timezone-for-activerecord-in-rails3 – Richard Peck Nov 12 '13 at 09:41
  • No problem! If you need any more help, let me know :) – Richard Peck Nov 12 '13 at 09:45
0

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/

astropanic
  • 10,800
  • 19
  • 72
  • 132