gpt4 book ai didi

ruby-on-rails - 如果是elsif,则HAML中的语法错误

转载 作者:行者123 更新时间:2023-12-03 08:01:44 25 4
gpt4 key购买 nike

当我尝试渲染HAML部分内容时,我一直收到此错误:

app/views/shared/_notification.html.haml:9: syntax error, unexpected keyword_elsif, expecting keyword_end
app/views/shared/_notification.html.haml:17: syntax error, unexpected keyword_elsif, expecting keyword_end
app/views/shared/_notification.html.haml:25: syntax error, unexpected keyword_elsif, expecting end-of-input
app/controllers/application_controller.rb:20:in `notify_in_realtime'
app/controllers/account/users_controller.rb:38:in `show'

当我尝试渲染此 View 时:
- if object.class.name == 'Lab'
= link_to account_lab_path(object), "data-id" => notification.id.to_s, :class => "notification item"
= image_tag object.picture.url(:medium), :class => "img-circle pull-left avatar"
.media-body
%strong.name
= object.title
= content

- elsif object.class.name == 'Post'
= link_to account_lab_path(object.lab, :post => object.id), "data-id" => notification.id.to_s, :class => "notification item"
= image_tag object.lab.picture.url(:medium), :class => "img-circle pull-left avatar"
.media-body
%strong.name
= object.lab.title
= content

- elsif object.class.name == 'Comment'
= link_to account_lab_path(object.post.lab, :comment => object.id), "data-id" => notification.id.to_s, :class => "notification item"
= image_tag object.post.lab.picture.url(:medium), :class => "img-circle pull-left avatar"
.media-body
%strong.name
= object.post.lab.title
= content

- elsif object.class.name == 'User'
= link_to account_user_path(object), "data-id" => notification.id.to_s, :class => "notification item"
= image_tag avatar_url(user, :thumb), :class => "img-circle pull-left avatar"
.media-body
%strong.name
= object.full_name
= content

- elsif object.class.name == Mailboxer::Conversation
= link_to account_conversation_path(object), "data-id" => notification.id.to_s, :class => "notification item"
= image_tag avatar_url(user, :thumb), :class => "img-circle pull-left avatar"
.media-body
%strong.name
= user.full_name
= content
.clearfix

在我的应用程序 Controller 内部,我试图将其存储在变量中以供以后发送:
html = render_to_string :partial => 'shared/notification', :locals => {content: content, user: user, object: object, notification: notification}

任何帮助表示赞赏,谢谢。 :)

最佳答案

haml语法不正确

如果要在链接中包含图像和.media-body,则应在do之后添加link_to,否则它们应与link_to处于同一级别

- if object.class.name == 'Lab'
= link_to account_lab_path(object), "data-id" => notification.id.to_s, :class => "notification item" do
= image_tag object.picture.url(:medium), :class => "img-circle pull-left avatar"
.media-body
%strong.name
= object.title
= content
...

关于ruby-on-rails - 如果是elsif,则HAML中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32243370/

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