gpt4 book ai didi

ruby-on-rails - 带if语句的Users#show中的语法错误

转载 作者:行者123 更新时间:2023-12-03 08:30:16 26 4
gpt4 key购买 nike

因此,我有这个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行。有人看到出什么问题了吗?

最佳答案

else if current_user

您无法在 ruby 中做到这一点。为此有一个特殊的关键字 elsif
if a
# ...
elsif b
# ...
elsif c
# ...
else
# ...
end


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

在此处删除 do

关于ruby-on-rails - 带if语句的Users#show中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19732239/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com