Ruby 的助手

发布于 2024-12-21 18:05:05 字数 606 浏览 1 评论 0原文

我正在为一些剪贴板复制代码制作一个助手。我希望剪贴板复制视图中生成的 url。

例如,以下是在视图中有效的链接:

<%= link_to event_path(event.id) %>

它在视图中工作得很好。我很难弄清楚该把它放在哪里作为助手。我在助手中传递一个变量,那么我应该将其放入视图中并将其传递给变量,还是应该将其放入助手中?现在它在助手中,我得到正常的文本。

这是 helper.rb 文件:

def clipboard_copy(text = nil, bgcolor='#FFFFFF')
  html = <<-EOF
        ...
    <param NAME="FlashVars" value="text=#{text}">
           ...
           FlashVars="text=#{text}"
           ...
EOF
html.html_safe
end

我从视图中调用它:

<%= clipboard_copy %>   

谢谢!

I am making a helper for some clipboard copy code. I would like the clipboard to copy a url that is generated in the view.

For example, here is the link that works in the view:

<%= link_to event_path(event.id) %>

It works just fine in the view. I am having a hard time figuring out where to put it for the helper. I am passing a variable in my helper, so should I put it in the view and pass it to the variable or should I put it in the helper? Right now it's in the helper and I get normal text back.

Here is the helper.rb file:

def clipboard_copy(text = nil, bgcolor='#FFFFFF')
  html = <<-EOF
        ...
    <param NAME="FlashVars" value="text=#{text}">
           ...
           FlashVars="text=#{text}"
           ...
EOF
html.html_safe
end

and I am calling it from the view with:

<%= clipboard_copy %>   

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2024-12-28 18:05:05

这看起来似乎并不真正需要辅助方法 - 您是否尝试过将其放入部分中,将文本(以及我猜的背景颜色)作为局部变量传递给该部分?

This looks like it doesn't really need a helper method - have you tried putting it in a partial, passing the text (and, I guess, the bgcolor) as locals to that partial?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文