Solved

Tidy Ruby on Rails Code

Posted on 2010-09-08
2
784 Views
Last Modified: 2013-11-13
I have recently gotten some really messy and hard to read code from my ruby developer..
looks like this:
<%- unless current_user %>
  <div id="login-dialog" class="columns clearfix" >
    <div id="login-dialog-left" class="col-5">
      <div class="login-message">

bascially just some ruby and html together

 what can I use to automatically put in tabs and spaces etc..?
0
Comment
Question by:hubfub
2 Comments
 
LVL 12

Accepted Solution

by:
JESii earned 250 total points
ID: 33626038
First off, I would say that this is pretty standard ERB (embedded ruby code) that is used in Rails to dynamically lay out a page, depending on the value of variables such as "current_user". There will be quite a bit of that in a Rails application.

For tabs, I assume that you mean automatic indentation depending on the structure...right? In that case you can open the code in your favorite IDE and have it do the job. I use Rubymine (http://www.jetbrains.com/ruby/index.html) myself, but there's also Aptana (http://aptana.com/) and NetBeans (http://netbeans.org/) or even TextMate (http://macromates.com/) if you're on a Mac. Depending on your experience, the vim editor (http://www.vim.org) also has automatic indentation using the '=' command and the :cindent option.

For spaces, I'm not sure what you mean. The code snippet you show is correctly formatted. If you're thinking of adding spaces surrounding the "=" in 'id="login-dialog"' I would not recommend that: there are generally no spaces between an attribute name ('id'), the equal sign, and the attribute value ('login-dialog'). Take a look at the W3C HTML tutorial (for example http://www.w3schools.com/html/html_attributes.asp) to see what I mean.
0
 
LVL 10

Assisted Solution

by:Andrew Doades
Andrew Doades earned 250 total points
ID: 33642384
Netbeans is certainly my favourite!
I will always recommend Netbeans to any ruby/ ruby on rails developer.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now