Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How to stay strictly in Ruby ?

Rails • Asked by Tommy

Hello, I'm a newbie at Rails. Let's say I have this simple form:

<%= form_for @article do |f| %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :description %>
<%= f.text_area :description %>
<%= f.submit %>
<% end %>

This form works fine. But, what I would prefer to do is this:

form_for @article do |f|
f.label :title
f.text_field :title
f.label :description
f.text_area :description

See how clean the code is! Consider if this were a large form, carrying along the open and close Ruby tags (<%=) and (%>) EVERY single line would be a pain in the neck and inefficient! Now, let's say if I need to include any HTML tag (such as p or br) to render the form the way I want, is there a way to include any HTML tag OR text without leaving Ruby ? I know I can easily achieve this if I were to code in PHP. It would be a distraction to switch back and forth between Ruby and HTML, especially when working with a large form.

If less typing is what you solely after, you might be interested in Slim or Haml.

eelcoj, I appreciate your response! It's not about less typing, it's about keeping the code clean and compact. Thanks!

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.