nk06 nk06 - 6 months ago 16
Ruby Question

How to write this in ruby on rails?

<div id="datetimepicker" class="input-append date">
<input type="text"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>


This is what I could come up with. And it was wrong!

<%= text_field_tag('datetimepicker',
content_tag(:span,
content_tag(:i,
{data-time-icon:'icon-time'},
{data-date-icon:'icon-calendar'}
),
{class: 'add-on'}
),
{class: 'input-append'}
)%>


Any help would be greatly appreciated.

Answer

text_field_tag is for input, for other you can use content_tag

This is your current markup:

<div id="datetimepicker" class="input-append date">
  <input type="text"></input>
  <span class="add-on">
    <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
  </span>
</div>

Using Rails helpers it can be modified to :

<%= content_tag :div, :class=> "input-append date", :id => 'datetimepicker' do %>
  <%= text_field_tag '' %>
  <%= content_tag :span, :class => "add-on" do %>
    <%= content_tag :i, :data => {:time-icon => 'icon-time', :date-icon => 'icon-calendar'} %>
  <% end %>
<% end %>

However I prefer Basic HTML over these ActionView Helpers, unless its helping out with code, which in this case is not much..