rails link_to body with action parameter?

时间:2018-02-04 06:29:29

标签: ruby-on-rails link-to

我有一个文章表和一个回复表。 文章中有一栏' reply_count'。在视图中,我想在我的link_to中显示回复计数,但我不知道该怎么做。

此处的控制器代码

class ArticleController < ApplicationController

  def index
    @article = Article.all
  end

end

此处的文章视图

<%= link_to 'Reply(<%= article.replies_count %>)', path %>

我希望它可以像这样显示

<a href=path> Reply(2) </a>

需要大家的帮助,谢谢...

1 个答案:

答案 0 :(得分:1)

字符串插值是关键字。请注意双引号,它会使#{}有效

<%= link_to "Reply #{article.replies_count}", path %>

相关问题