I'm using sinatra and following this tutorial here and I have tried rewrite this code with HAML:
<form action="/task/create" method="POST">
<input type="text" name="name" id="name">
<input type="submit" value="Add Task!"/>
</form>
<h2>Tasks:</h2>
<% unless @tasks.empty? %>
<ul>
<% @tasks.each do |task| %>
<li <%= "class=\"completed\"" if task.completed_at %>>
<a href="/task/<%=task.id%>"><%= task.name %></a>
</li>
<% end %>
</ul>
<% else %>
<p>No Tasks!</p>
<% end %>
Here is my HAML code:
%form{action: "/task/create", method: "POST"}
%input{type: "text", name: "name", id: "name"}
%input{type: "submit", value: "Add Task!"}
%h2 Tasks:
- unless @tasks.empty?
%ul
- @tasks.each do |task|
%li= "class=\"completed\"" if task.completed_at
%a{href: "/task/#{task.id}"}= task.name
- else
%p No Tasks!
And I get the following error when I try to look at the page:
Haml::SyntaxError at / Illegal nesting: content can't be both given on the same line as %li and nested within it.
Any helps on this would be great.
Ivo