【发布时间】:2013-04-05 16:16:44
【问题描述】:
我正在编写一个小型论坛应用程序,用户可以在其中创建不同类型的论坛。例如,公告、讨论或问题论坛。
论坛模型有很多帖子,还有一个forum_type 专栏。我想根据@post.forum_type 列使用不同的模板渲染posts#show。
因此,每个论坛根据其类型,其帖子都会有不同的外观。
我怎样才能做到这一点而不用if @post.forum_type == 'something' 乱扔我的代码...?
【问题讨论】:
-
在其他想法中,如果您只使用类似:
render :template => 'forums/forum_type_here'但在render语句中使用@post.forum_type变量...类似这样:render :template => @post.forum_type? (或者如果它是一个字符串,也可以在@post.forum_type变量上附加一些东西。) -
好主意。没有我想要的那么干净,但是一个很好的选择。
标签: ruby-on-rails ruby templates rendering