【发布时间】:2015-10-02 02:29:01
【问题描述】:
所以我使用相同的部分来列出博客项目并显示完整项目。问题是详细视图不需要包含博客图像和博客标题中的链接。这种情况下的最佳做法是什么?
我想检查一个确定是否调用详细视图的局部变量,但不知何故我无法让它工作:
呼叫:
render @post, locals: {detail: 'true'}
部分:
link_to post.title, post if not defined? detail
但不知何故,局部变量并没有传递给局部变量。
编辑:
好的,我现在更进一步:
#index.html.haml
= render @posts
#show.html.haml
= render @post
#post/_post.html.haml
= post_counter
编辑2:好的,解决了...有点头疼,嵌套在haml中的if语句需要完整的括号
#post/_post.html.haml
.blog-post
.blog-post-image
= (defined? post_counter) ? link_to(image_tag(post.cover_image(:large)), post) : image_tag(post.cover_image(:large))
【问题讨论】:
-
请发布完整的部分和全部
标签: ruby-on-rails