Question

I have an app, and I have it running locally. I can create another version of the app in rails console, however I want to have a command line interface for the app that is running that I can interact with both in the web interface and the console.

Ideally I fire up rails s and then can play with the variables in that environment.

Was it helpful?

Solution

You can't do this with vanilla Rails. Each time you type rails (whether with server or console), you're booting a brand new instance of your application, which shares no state with any other instance.

However, if you install the extremely useful Pry gem, you can type binding.pry at any point in your application (inside an action or model or view). When program flow hits your binding.pry, the server instance will drop into an interactive shell, and you can inspect the state of your server process. This is about as close as you can get to what you're trying to do.

OTHER TIPS

If I'm reading your question correctly, this is common to do.

You can have rails s running in one terminal window within your app directory, then have rails c running in another terminal window within the same app directory.

You can then modify objects in the DB which will be visible within the web UI.

Responding to "I love pry!!!" - you are generally asking how to "debug" your app. So, if you install RubyMine (and a handful gems such as debug_inspector, debugger, debugger-linecache, debugger-ruby_core_source, pry-debugger, & ruby-debug-ide), then you can run your rails server from RubyMine's debugging Configuration.

From there, you can put a breakpoint where you would have pry-ed. And you can run statements in RubyMine, to see what's going on. And RubyMine makes an awesome platform for refactoring and automated testing. No affiliation; just providing more answers for the question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top