0

所以我有这个 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 行。有人知道出了什么问题吗?

4

2 回答 2

1
else if current_user

你不能在红宝石中做到这一点。有一个特殊的关键字,elsif.

if a
  # ...
elsif b
  # ...
elsif c
  # ...
else
  # ...
end

<% unless current_user?(@user) do %>

去掉do这里。

于 2013-11-01T17:56:39.780 回答
0

修复它:原来你不能unless那样使用,我把它改成了一个 If 语句

于 2013-11-01T20:36:28.640 回答