Tommy

Joined

60 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in How to stay strictly in Ruby ?

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

Posted in How to stay strictly in Ruby ?

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
f.submit
end
%>

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.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.