Apply Ruby on Rails comment in Dreamweaver
So, lately I have been teaching myself Ruby on Rails, using the Sitepoint book, “Build Your Own Ruby on Rails Web Applications” by Patrick Lenz. In the process I have been checking out various development tools to work with Rails.
The first tool I tried was Aptana’s RadRails. RadRails has a lot of functionality, gets great reviews, and seems really cool, however… I couldn’t get it to work properly with my existing RoR project. When I import my project, and start the server, I cannot run the project in my browser. It works fine if I use the command line way, so I know this is something I’m missing with Aptana. I didn’t want to spend (waste?) a lot of time figuring that out, so I moved on to the next tool:
UltraEdit. This is a more basic file editing tool that contains all the things you really need to work in a Rails project — syntax highlighting, etc.
Tonight I started looking into using Dreamweaver to edit Rails files, since Dreamweaver is something I’m very familiar with, and it has long been my web tool of choice. Dreamweaver has code completion, and who doesn’t love that. However, it does not include that for Ruby files. But there is an extension available called Rubyweaver that does take care of Ruby syntax highlighting and code completion. I thought this would be just what I was looking for.
I was mostly right, with one minor exception: Code commenting. Within Dreamweaver there is a toolbar that allows you to quickly comment code with one of the following options: HTML, ” // “, ” /* “, or “ ‘ “. After installing the Rubyweaver extension, I was disappointed to see that there was no ” # ” comment in the toolbar. So, I set about finding a way to add it myself.
I found some useful configuration files in the \Configuration directory of my local Dreamweaver installation.
You can add different comment types to the context menu by modifying the \Menus\menus.xml file. For example, to add the # comment type that I wanted I inserted the following line at line number 918:
menuitem name="Apply # Comment" domrequired="false" enabled="dw.getFocus(true) == 'textView' || dw.getFocus(true) == 'html'" command="dw.getDocumentDOM().source.applyComment('#', '')" id="DWContext_HTML_Selection_ApplyRubyComment">
Likewise I added the following line at number 924 to remove the # comment:
menuitem name="Remove # Comment" domRequired="false" enabled="dw.getFocus(true) == 'textView' || dw.getFocus(true) == 'html'" command="dw.getDocumentDOM().source.removeComment('#')" id="DWContext_HTML_Selection_removeRubyComment"
As I said earlier, these lines of code add the # comment option to the (right-click) context menu. In other words, within a file you are editing, you would highlight the line(s) you want to comment, right-click on them, and choose Selection… > Apply # Comment. To remove the comment you would highlight the commented lines, then right-click and choose Selection… > Remove # Comment.
As of yet I have not figured out how to add the # comment option to the graphical Apply Comment button that appears in Code View. I’m working on it though…
I hope this helps out someone else working with Ruby on Rails files within Dreamweaver!