我正在 ruby 中迈出第一步,我正在尝试学习如何使用 Sinatra。在一本相关的书中,我发现这个示例视图是用 Slim 编写的。
h1 Songs
a href="/songs/new" Create a new song
- if @songs.any?
ul#songs
-@songs.each do |song|
li <a href="/songs/#{song.id}">#{song.title}</a>
- else
p No songs have been created yet!
我试图将其更改为 ERB,结果是这样的
<html>
<h1> Songs </h1>
<a href="/songs/new" Create a new song></a>
<% if @songs.any? %>
<%#songs%>
<% @songs.each do |song|%>
<ul><li> <a href="/songs/#{song.id}"><%=#{song.title}%></a></li></ul>
<% else %>
<p> No songs have been created yet!</p>
<% end %>
</html>
Sinatra 给了我这份报告
SyntaxError at /songs
Documents/programs/sinatra/views/songs.erb:8: syntax error, unexpected keyword_else, expecting ')' ; else ^
Documents/programs/sinatra/views/songs.erb:10: syntax error, unexpected keyword_end, expecting ')' ; end ; @_out_buf.concat "\t\n" ^
Documents/programs/sinatra/views/songs.erb:14: syntax error, unexpected keyword_ensure, expecting ')'
Documents/programs/sinatra/views/songs.erb:16: syntax error, unexpected keyword_end, expecting ')'
你能给我一个线索吗?先感谢您。