Solved

Tidy Ruby on Rails Code

Posted on 2010-09-08
2
789 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 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