【问题标题】:Put a relative link button in Rails Action Text在 Rails 操作文本中放置一个相对链接按钮
【发布时间】:2021-03-07 21:55:33
【问题描述】:

在 .html.erb <%= link_to 'the listing', "years/1846", class: "btn btn-primary" %> 中有效。如何将其放入操作文本字段并使其成为链接?

它将被硬编码到如图所示的特定记录。 years 是我的应用程序中的表格、模型等。不必是 Bootstrap 按钮,但确实需要看起来像一个链接,因此需要设置样式。

【问题讨论】:

    标签: ruby-on-rails link-to actiontext


    【解决方案1】:

    您可以将 link_to 代码的原始 html 输出直接添加到 ActionText 字段,它应该可以工作。像 roster.description += ‘the Listing’ 等(显然 roster 和 description 是 ActiveRecord 对象和 ActionText 字段名称的占位符名称)

    【讨论】:

    • 谢谢,但我不明白你的建议。 ActionText 是 docs/_form.html.erb,字段名称是 content。所以doc.content += <a href "/years/1846">the listing</a>' which is still rendered literally. It can't be entered into the link helper that Rails Action Text provides because that has to start with http`.
    • 嗯,很抱歉,但我想我不清楚所需的输出是什么。为什么不直接像这样手动输入html链接,然后:<a href='http://yourdomain.com/years/1846>the listing</a>
    • 除非在开发期间,这可能会起作用,我在 localhost:3000 的开发期间添加数据。
    • True.... 一种解决方法是创建一个辅助方法,该方法使用 gsub 和 Rails.env 来动态决定在视图中显示哪个服务器。
    • 谢谢。即使我知道该怎么做,也可能会更复杂。但也许我会调查一下。或者也许创建另一个包含所需信息的字段。或者其他方式
    猜你喜欢
    • 1970-01-01
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-01
    • 2019-05-26
    • 2015-07-24
    相关资源
    最近更新 更多