How to debug Rails app with eclipse on Ubuntu.(steps into,steps over,steps out)

How to debug Rails app with eclipse on Ubuntu.(steps into,steps over,steps out)

How to debug Rails app with eclipse on Ubuntu.(steps into,steps over,steps out)

22 Comments on How to debug Rails app with eclipse on Ubuntu.(steps into,steps over,steps out)

I introduce you, how to debug Ruby on Rails Application with Eclipse.

Hi,I’m japanese. So my english ability is poor. Just be patient.

Install Eclipse and JDK

Download JDK from Oracle web site.
Download Eclipse from Eclipse web site.

I install JDK and Eclipse into /usr/java.

[bash]
$ sudo mkdir /usr/java
$ sudo mv ~/Downloads/eclipse-standard-kepler-SR1-linux-gtk.tar.gz /usr/java
$ sudo mv ~/Downloads/jdk-7u51-linux-i586.tar.gz /usr/java/

$ cd /usr/java
$ sudo tar xvzf jdk-7u51-linux-i586.tar.gz
$ sudo tar xvzf eclipse-standard-kepler-SR1-linux-gtk.tar.gz
[/bash]

Setting environment variables

add this settings into ~/.bashrc

[bash]

JAVA_HOME=/usr/java/jdk1.7.0_45
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=$JAVA_HOME/jre/lib/rt.jar

export JAVA_HOME PATH CLASSPATH

[/bash]

refresh environment variables and check JAVA_HOME.
[bash]
$ source ~/.bashrc
$ echo $JAVA_HOME
/usr/java/jdk1.7.0_45
[/bash]

Install Aptana plugin

On Eclipse Menubar, Help > Install New Software.

push Add button and input this url.

http://download.aptana.com/studio3/plugin/install

and click OK to install plugin.

Screenshot from 2014-01-19 05:29:00

Screenshot from 2014-01-19 05:29:15

Creating Rails project

On Eclipse Menubar, File > New > Other

メニュー_002

メニュー_001

select Rails Project and click Next.
Screenshot from 2014-01-19 05:38:53

input Project Name “testproj” . Click Finish.

Screenshot from 2014-01-19 05:39:37

Start webric server

[bash]
$ cd ~/workspace/testproj
$ rails s

Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
[/bash]

if “Could not find a JavaScript runtime” is shown ,install nodejs.

[bash]
$ sudo apt-get install nodejs
[/bash]

if you use mysql, install libmysqlclient-dev.

[bash]
$ sudo apt-get install libmysqlclient-dev
[/bash]

Test Running

[bash]
$ rails s

=> Booting WEBrick
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-01-16 16:59:59] INFO WEBrick 1.3.1
[2014-01-16 16:59:59] INFO ruby 2.0.0 (2013-11-22) [i686-linux]
[2014-01-16 16:59:59] INFO WEBrick::HTTPServer#start: pid=19531 port=3000
[/bash]

Access Rails app with your browser.
URL is http://localhost:3000

if the top page is shown,please shutdown rails server with Ctrl + C key.

rails-1

Debugging with Eclipse

On Eclipse Menubar, Window > Show View > Servers.

メニュー_003

Bottom of Eclipse, Server view is shown.
Select testproj ,and click Edit button.

Web - Eclipse _004

Here is very very important Point!!
As a default, value of Host/IP is 0.0.0.0 , change 127.0.0.1 !!
and click OK.

Edit your Rails Server settings. _005

click debug button for debugging rails.

Web - Eclipse _006

if “Ruby program /home/xxx/workspace/testproj/script/rails does not exist.” is shown, create script folder.

[bash]
$ cd ~/workspace/testproj
$ cp bin/ script -R
[/bash]

Problem Occurred _007

install IDE debugger.
[bash]
$ gem install ruby-debug-ide
[/bash]

Create a sample application

[bash]
$ rails generate scaffold Sample name:string email:string
$ rake db:migrate
[/bash]

Test Running

click debug button on server view for debugging rails.
access http://localhost:3000/samples with your browser.

Web - Eclipse _006

Testproj - Chromium_010

Now debugging with eclipse

Open app>>controllers>>samples_controller.rb from Eclipse Project Explorer.
and set break point.

Web - testproj-app-controllers-samples_controller.rb - Eclipse _008

[bash]
def index
@samples = Sample.all
end
[/bash]

reload the page with your browser.

if a screen like this is shown .you get a debugging environment of Rails app.Congratulations!

Debug - testproj-app-controllers-samples_controller.rb - Eclipse _009

About the author:

Related Posts

Back to Top