所以我有这个ERB部分,根据传递的局部参数呈现不同的部分:
<% unless current_user?(@user) do %>
<div id="relation">
<% if current_user.friends?(@user) %>
<%= render('edit-relation', locals: { action: "rm-friend" })%>
<% elsif current_user.req_friends?(@user) %>
Friend Request Pending...
<% elsif current_user.pend_friends?(@user) %>
<%= render('edit-relation', locals: { action: "add-friend" })%>
<%= render('edit-relation', locals: { action: "rej-friend" })%>
<% else %>
<%= render('edit-relation', locals: { action: "req-friend" })%>
<% end %>
</div>
<% end %>
抛出语法错误:
Showing C:/Users/HP/Ubuntu One/A2 Computing Project/Software Development/Client/app/views/layouts/_relation.html.erb where line #15 raised:
C:/Users/HP/Ubuntu One/A2 Computing Project/Software Development/Client/app/views/layouts/_relation.html.erb:15: syntax error, unexpected keyword_ensure, expecting keyword_end
C:/Users/HP/Ubuntu One/A2 Computing Project/Software Development/Client/app/views/layouts/_relation.html.erb:17: syntax error, unexpected end-of-input, expecting keyword_end
没有15号线或17号线。有人看到出了什么问题吗?
答案 0 :(得分:1)
else if current_user
你不能在红宝石中这样做。有一个特殊的关键字elsif
。
if a
# ...
elsif b
# ...
elsif c
# ...
else
# ...
end
<% unless current_user?(@user) do %>
在这里删除do
。
答案 1 :(得分:0)
修正了它:结果你不能像这样使用unless
,而是将它改为if语句而不是