randombits
randombits

Reputation: 48440

How to write the following HTML in HAML

I am working on converting some HTML to HAML. I am attempting to output the following in a Ruby on Rails form:

<p>Date: <input type="text" id="datepicker"></p>

What's the best way to convert this to HAML? I tried something like:

=f.input#datepicker{:type => 'text'}

But that doesn't work.

I've also tried the following without much luck:

 %p
    Date
    = f.text_field {:id => 'datepicker'}

Upvotes: 0

Views: 370

Answers (2)

Raichel
Raichel

Reputation: 106

The = is for evaluating Ruby code and outputting it to the page, which is why it does not work for you. You're mixing Ruby with HAML conventions.

If you want to use the Ruby form helpers, you should do the following:

%P
    Date:
    = f.text_field <ATTRIBUTE_NAME>, {:id => 'datepicker'}

Upvotes: 2

Roman Kiselenko
Roman Kiselenko

Reputation: 44360

%p
  Date:
  %div{ :id => 'datepicker' }
    = f.input

Upvotes: 0

Related Questions