Rubymine: debugging using installed Puma-dev? - ruby-on-rails

Is it possbile to have Rubymine connect to (and restart) an installed/running instance of Puma-dev for the debugging session?
I use Puma-dev to test my Rails app on "Appname".test, yet if I need to debug something in the app and want to use Rubymine's built-in debugger, I can only let it start an additional instance of Puma on Port 3000 (or whatever Port I choose) but not the already running Puma-dev on port 80/443.
Is it at all possible?

This is possible with remote debugging. To configure, you have to make some changes to your app:
Add export RUBY_DEBUG_PORT=1234 to .env or .powenv or any file puma-dev will load an environment variable from. Feel free to use whatever port you'd like, although RubyMine uses 1234 by default.
Add the ruby-debug-ide and debase gems to your project's Gemfile.
Add an initializer to your project to initialize remote debugging, like so:
if Rails.env.development? && ENV['RUBY_DEBUG_PORT']
Debugger.start_server nil, ENV['RUBY_DEBUG_PORT'].to_i
end
Restart puma-dev.
Go to Edit Configurations in RubyMine and add a "Ruby remote debug" config. Name it whatever you'd like. Change the port to the port you set via RUBY_DEBUG_PORT. Set your local and remote root folders to your project root.
Select your newly created configuration and click the Debug button. It should connect to the debugger running in your puma-dev process.

Related

How to run ruby on rails application in RubyMine IDE

In python/flask, file app.py can be called from an IDE or the console to run an entire web application.
In Ruby on Rails, I use bin/rails server in the console to start a server to run the rails app, but I am having a hard time doing the same in RubyMine IDE. I tried running application_controller.rb file, but nothing happened.
Which file should I run in IDE to start the server and see the web app in action?
To run a Rails server from the reference Ruby Mine Doc
Press Shift+Alt+F10, and choose the desired Rails run/debug
configuration type.
If necessary, change the run/debug configuration settings. To do
that, choose Edit configurations... in the Run popup menu, and
choose the desired Rails configuration type. Rails run/debug
configuration dialog box appears.
In this dialog box, modify the desired settings. For example,
RubyMine suggests WEBrick as the default Rails server. You can
select a different server from the list of supported servers.
Click the I> button on the main toolbar.

Rails app deployed on Centos w/ standalone Passenger and Capistrano can't access ENV variables

I set up a Centos 7 VM using this tutorial (standalone passenger) and RVM. I am deploying the rails app via Capistrano.
https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/standalone/oss/install_language_runtime.html
Everything seems to work, except no matter where I set environment variables, the ENV["myvar"] can't be read in Rails.
I've tried export myvar=test SSHed as the "deployers" as well as root. I've also tried adding it to bashrc. If I login as deployer and do the following:
#symlink to current capistrano deploy
cd ~/rails/railsapp/current/
rails r "puts ENV['myvar']"
It gives me the correct ENV output. However, if I try to output ENV['myvar'] from my actual deployed via capistrano rails app, I get nothing.
Where am I supposed to set these ENV vars? I know the ENV vars in rails are done correctly, because the app deployed to heroku, as well as on my dev machine, correctly output ENV['myvar'].
Generally, your setup should work. Since version 4, a standalone Passenger should inherit all variables defined in the shell startup scripts. There is a nice documentation about environment variables in various scenarios related to using Passenger.
I would check or two things:
That your .bashrc is loaded from .profile. If it weren't, then your variables would be loaded only in an interactive shell but not in passenger, which would explain the behavior your describe when you tried to log in as the deployers. Let me quote from the doc:
Make sure your ~/.bashrc is actually included by your ~/.profile, which might not be the case if you created the user with useradd instead of adduser for example.
Also, take a look at this section of the docs and check that you obey the conditions upon which Passenger actually passes the environment vars to the application.

How do we run some OS command when Rails is starting?

I need to run a command after or before starting Rails. It will start a server on port 9292 so my chat app will work.
This command should preferably be executed automatically with Rails (on production and development).
How do we do that in Rails 4?
Is Capistrano the only option? Can we schedule it to be executed when Rails starts?
Use capistrano and forman or systemd to manage your chat server instance, like, for example you would do for sidekiq.
A good start would be : http://anlek.com/2015/01/using-foreman-with-upstart-capistrano/
You have 2 options that I know of if you don't want to use Capistrano. In your config/application.rb
config.after_initialize do
# ....
end
http://guides.rubyonrails.org/configuring.html
or you can write a custom initializer that is run with on_server_start event.
There's a whole section of config/ intended for startup behavior: config/initializers/. If you need to do anything as part of the startup of your app, you can create an initializer file here, and it will automatically get run as Rails starts.
To do this, simply create a new file: config/initializers/chat_app.rb:
# This file will start and establish an initial connection to the chat app
`chat-app --some-arg` # <== The chat app
We use this for various startup and system sanity checks for the application. It's independent of your deployment, so if you need it for other deployment purposes, creating a Capistrano (or even Rake) task is the better option.

Ruby Passenger displays content from public instead of the app

I have a server in the cloud. I've set up a Linux machine with Apache2 + Passenger(with the apache module installed).
I've configured by the book, set up the VirtualHost as the Passenger instructions tell me to.
I've created a default Ruby on Rails project in "RubyMine"(on the local machine), synchronized it with the server.
Here is the project file hierarchy:
Since the instructions ask me to point in the configuration file to /projectFolder/public, I did so. If there is no index.html in the public folder, it throws me an error, if I create one it displays it when I access the link.
But when on the local machine I deploy it, it instead launches the app from app->views->layouts.
How to make it run on the remote server my ruby code? My ruby "app"?
First try:
sudo passenger-status
This should show you if passenger is loaded and the applications group. If that is all good, delete the index.html from /public and restart apache.

How do you stop bundler from showing pasword on screen when using capistrano?

I have a question regarding capistano and bundler.
When I deploy my app via ssh copy, bundler asks me for my root password. This is fine because I'm installing my gems to a seperate directory on the system. However, when I type my password it shows up on the screen when I type it. How do I get this to stop?
I'm using current stable versions of Rails, Bundler, Capistano. System is running FreeBSD 9.0, Apache and Phusion Passenger.
Thank you.
The way we do it is to useforwarding, and then capistrano will use your ssh key to get into the server.
ssh_options[:username] = 'USERNAME'
ssh_options[:forward_agent] = true
this way, you don't have to use passwords. You just have to have your key in the ~/.ssh/authorized_keys file, and configure your server to do forwarding. Some Googling should yield steps on how to set up forwarding on your OS, but if it's Ubuntu, the ubuntu ssh documentation is a good place to start

Resources