gpt4 book ai didi

ruby-on-rails - Rails,设计和 Haml : syntax error, 意外 kELSE

转载 作者:行者123 更新时间:2023-12-04 18:24:07 24 4
gpt4 key购买 nike

我正在尝试设置一个简单的应用程序来运行多个博客,我的 app/views/layouts/application.html.haml 文件如下所示:

!!!
%html
%head
%title Brimble's Blogs
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags

%body
%p.notice= notice
%p.alert= alert

.user-auth-nav{style => 'float:right'}
= if user_signed_in?
= link_to('Edit registration', edit_user_registration_path)
= link_to('Logout', destroy_user_session_path)
= else
= link_to('Login', new_user_session_path)
= link_to('Register', new_user_registration_path)
= end

= yield

我得到的错误是:
compile error
<myapp>/app/views/layouts/application.html.haml:18: syntax error, unexpected kELSE
<myapp>/app/views/layouts/application.html.haml:22: syntax error, unexpected kEND
<myapp>/app/views/layouts/application.html.haml:23: unknown regexp options - htl
<myapp>/app/views/layouts/application.html.haml:23: syntax error, unexpected $undefined
));}\n </div>\n</html>\n#{_hamlout.adjust_tabs(-2); _...
^
<myapp>/app/views/layouts/application.html.haml:25: syntax error, unexpected kENSURE, expecting $end

提取的源代码(大约第 18 行):
15:       = link_to('Edit registration', edit_user_registration_path)
16: = link_to('Logout', destroy_user_session_path)
17: = else
18: = link_to('Login', new_user_session_path)
19: = link_to('Register', new_user_registration_path)
20: = end
21:

我正在关注此页面上的教程:
http://www.logansbailey.com/2011/02/27/adding-authorization-using-devise/
本教程使用 erb,但我真的很喜欢 Haml 的想法,所以我想试一试。

提前致谢

最佳答案

对于不应输出内容的 ruby​​ 代码,请使用 -而不是 = :

  .user-auth-nav{style => 'float:right'}
-if user_signed_in?
=link_to('Edit registration', edit_user_registration_path)
=link_to('Logout', destroy_user_session_path)
-else
=link_to('Login', new_user_session_path)
=link_to('Register', new_user_registration_path)
end在haml中可以省略标签。

关于ruby-on-rails - Rails,设计和 Haml : syntax error, 意外 kELSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10054846/

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