Use rails-footnotes to open files in NetBeans from Firefox
Here is how to use rails-footnotes with NetBeans on linux!
- Clicking on the link …
- … opens the file in Netbeans
Thanks to José Valim we have a nice new plugin for better debugging of Rails applications! In his blog post he describes how to open links to files on your hard disk with notepad++ on windows. I adapted this idea for opening files with netbeans on linux, and here is your way to go:
open about:config in firefox and add:
- string
network.protocol-handler.app.editorwith content~/.editor.rb - bool
network.protocol-handler.external.editorand set it totrue
create the file ~/.editor.rb and make it executable:
touch ~/.editor.rb && chmod +x ~/.editor.rb
And here is the content:
#!/usr/bin/ruby
file = ARGV.first.split('file://').last.split('&').first
line = /\&line\=(\d+)/.match(ARGV.first)[1] rescue 0
`"/path/to/your/netbeans-dir/bin/netbeans" "#{file}:#{line}"`
`wmctrl -a "NetBeans IDE"`
install wmctrl
sudo aptitude install wmctrl
We’ll need this to give focus to the NetBeans window.


March 31st, 2009 at 03:00
Hello Johannes,
I use netbeans on linux and I just installed Footnotes then I saw your post so proceeded to install it by following your directions above. I am not sure how to open “what” from firefox? When I run the application after installing footnotes, I see all the debugging links which I can click on to open and display the information, but how do I click on what links to display the code in NetBeans? Can you provide a bit more direction?
Thanks.
Bharat
March 31st, 2009 at 03:45
OK. I got past not being able to see the links for controller etc. I had forgotten to write the following line in my development.rb file under config/environments directory:
Footnotes::Filter.prefix = “editor://open?file://”
Now I did everything as you said above. Here is my .editor.rb file in my home directory:
bruparel@bcr-d810:~$ cat .editor.rb
#!/usr/bin/ruby
file = ARGV.first.split(’file://’).last.split(’&’).first
line = /\&line\=(\d+)/.match(ARGV.first)[1] rescue 0
`”/home/bruparel/netbeans-6.5/bin/netbeans” “#{file}:#{line}”`
`wmctrl -a “NetBeans IDE”`
bruparel@bcr-d810:~$ ll .editor.rb
-rwxr-xr-x 1 bruparel bruparel 216 2009-03-30 20:41 .editor.rb
And here are the entries from about:config in firefox:
network.protocol-handler.app.editor;~./editor.rb
network.protocol-handler.external.editor;true
But when I click on the links that appear on my Firefox browser window in my application. here is the message that I get:
Firefox doesn’t know how to open this address, because the protocol (editor) isn’t associated with any program.
How do I fix that?
Thanks for your time.
Bharat
March 31st, 2009 at 04:40
Sorry,
I had mistyped the value for network.protocol-handler.app.editor;~./editor.rb
It should have been network.protocol-handler.app.editor;~/.editor.rb
I made that correction and restarted everything. When I click on the link now I get the following message from netbeans instead of firefox:
/home/bruparel/editor:/open?file:/home/bruparel/exp/pizzaria-3/app/controllers/home_controller.rb&line=3&column=3 does not exist, or is not a plain file.
I do not know how to fix it. Do you think that the following line in my Rails_root/config/environments/development.rb is wrong?
Footnotes::Filter.prefix = “editor://open?file://”
This is wonderful. If I can get this to work, I will buy a you a whole pack of beer when you are in Boston.
March 31st, 2009 at 16:58
hey Bharat,
it is nice you figured out the most of the errors yourself.
nevertheless i will try to earn a pack of boston beer
in my opinion the error is indeed the line in your environment.rb. try to change it to
Footnotes::Filter.prefix = ‘editor://open?url=file://%s&line=%d&column=%d’
it would be nice when you report your progress!
Johannes
March 31st, 2009 at 19:51
Hello Yohannes,
Thanks for getting back to me. I replaced the line of code in my development.rb with the one that you have above:
Footnotes::Filter.prefix = ‘editor://open?url=file://%s&line=%d&column=%d’
First, NetBeans started complaining about unexpected ? mark in the editor. I think it is having trouble parsing the enclosing ‘ character that you have around the string ‘editor://open?url=file://%s&line=%d&column=%d’. I replaced it with the single quote character at both ends (’) and it parsed it correctly. but when I ran the program and clicked on the link, i got the same message. Next, I tried double quotes instead of single quotes and got the same result.
Next, I replaced both single quote character with back-tick characters as shown below:
Footnotes::Filter.prefix = `editor://open?url=file://%s&line=%d&column=%d`
And restarted the program again to reload it. This time I got the following message from the browser:
Routing Error
No route matches “/home/bruparel/exp/pizzeria-3/app/controllers/home_controller.rb&line=3&column=3″ with {:method=>:get}
The URL that it shows in the browser is as follows:
http://localhost:3000/home/bruparel/exp/pizzeria-3/app/controllers/home_controller.rb&line=3&column=3
I am on Ubuntu 8.10 and Firefox 3.0.8.
I am afraid you will have to work a bit harder for the Sam Adams beer my friend.
Look forward to hear from you.
Bharat
March 31st, 2009 at 20:40
ok, wordpress (the blogging engine i use) converts that single quotes to grave and accute accents but single quotes are definitely correct (as are double quotes). btw backticks (grave accutes) are the same as calling system, see here.
you write you get ‘the same message’ after replacing with single quotes. do you mean the message from netbeans you stated here?
/home/bruparel/editor:/open?file:/home/bruparel/exp/pizzaria-3/app/controllers/home_controller.rb&line=3&column=3 does not exist, or is not a plain file.when you hover the footnotes, can you post the link from Controller? it should be something like:
editor://open?url=file:///home/username/folder-to-your-application/app/controllers/example_controller.rb&line=5&column=3Johannes
March 31st, 2009 at 21:11
Ok Yohannes. here is the result of hovering over the footnotes link:
editor://open?url=file://%s&line=%d&column=%d/home/bruparel/exp/pizzeria-3/app/controllers/home_controller.rb&line=3&column=3
I see that it is quite a bit different than yours and may be that is the problem. Though I am not sure why the difference. Here is my ~/.editor.rb contents:
bruparel@bcr-d810:~$ cat ~/.editor.rb
#!/usr/bin/ruby
file = ARGV.first.split(’file://’).last.split(’&’).first
line = /\&line\=(\d+)/.match(ARGV.first)[1] rescue 0
`”/home/bruparel/netbeans-6.5/bin/netbeans” “#{file}:#{line}”`
`wmctrl -a “NetBeans IDE”`
bruparel@bcr-d810:~$
Thanks for your patience and time.
Bharat
March 31st, 2009 at 21:37
hmm…
which rails version do you use? you’ll find this information in the first lines of your
config/enviroment.rbwhich rails-footnotes version do you use? you’ll find this information in
vendor/plugins/rails-footnotes/READMEorvendor/plugins/rails-footnotes/CHANGELOGNote, this howto is for the ‘new’ rails-footnotes made by josevalim so you’ll need at least a
rails version >= 2.1andrails-footnotes version >= 3.2.2as i see it you are using at least a lower version of rails-footnotes?!
March 31st, 2009 at 21:54
This is from my config/environment file:
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = ‘2.1.2′ unless defined? RAILS_GEM_VERSION
And this is from vendor/plugins/rails-footnotes/CHANGELOG
TODO:
* Create ProfilerNote
== Footnotes v3.2.2
Author: José Valim (jose.valim@gmail.com)
Site: http://www.pagestacker.com/
* Added trace to QueriesNote;
* Fixed incompatibility with Ultrasphinx (thanks to mhartl);
* Added W3C compatibility (thanks to tapajos);
* Added support to other log mechanisms in LogNote.
I was careful in installing the correct version. By the way, I am on NetBeans 6.5.
March 31st, 2009 at 22:57
yep, i expected this. so you cannot use the script of my blog post because as i see it, this version of rails-footnotes doesn’t support the ‘line’ command. try this adapted script instead of the
~/.editor.rbabove:#!/usr/bin/ruby
file = ARGV.first.split('file://').last.split('&').first
`"/path/to/your/netbeans-dir/bin/netbeans" "#{file}"`
`wmctrl -a "NetBeans IDE"`
remember to change the line in the
config/environment.rbback to:Footnotes::Filter.prefix = "editor://open?file://"as stated here.note it is not working for me writing this in the
config/environments/development.rbbut it works when inconfig/environment.rb.when you get errors about “Footnotes not defined” try to do:
if defined?(Footnotes)
Footnotes::Filter.prefix = "editor://open?file://"
end
March 31st, 2009 at 23:47
No luck Yohannes. I have requested the NetBeans lead for Ruby to release a patch for Rails 2.3.2 for NetBeans 6.5 so that I can use your original recipe. Generally, they are very responsive to our needs so I expect Erno to do something fairly soon. I will keep you posted on how it works out.
. Seriously, if you are in here at all, look me up. We have pretty good Ruby and Rails community here.
Thanks a lot for trying. I still owe you that case of beer, you just have to come to Boston
Regards,
Bharat
April 1st, 2009 at 00:01
ok so good luck. once you have rails-footnotes working it is really a timesaver!
and believe me, once i am at boston i’ll come and visit you to drink some beers
April 13th, 2009 at 13:34
Thanks Johannes, I got it working after changing the shebang in .editor.rb to
#!/usr/local/bin/ruby
which is the ruby executable path when building Ruby 1.87 from source on Ubuntu and probably other configurations.
After installing the Netbeans fix suggested by Bharat which is at
http://www.netbeans.org/issues/show_bug.cgi?id=162287
it works great now save for some minor quirks. Thanks again!
April 30th, 2009 at 08:45
And when upgrading to Firefox 3 it might be necessary to remove (right-click and reset) the above settings in about:config, restart Firefox and then recreate the settings. Then, upon clicking a footnotes link, FF 3 will run a permissions dialog and put .editor.rb into the list at Edit > Preferences > Applications which is probably necessary for FF 3 to run external apps.