Ruby on rails Rails-使用文本字段作为数据属性的值

Ruby on rails Rails-使用文本字段作为数据属性的值,ruby-on-rails,twitter-bootstrap,Ruby On Rails,Twitter Bootstrap,我正在尝试实现一个按钮,该按钮显示一个引导弹出窗口,单击该窗口时会显示一个文本字段,用户可以键入他们想要与之共享帖子的人的电子邮件地址以下是迄今为止按钮的代码: <%= link_to collab_user_stories_path(@post), class: 'btn btn-default', title: 'Enter the email of the person you want to share this with:', 'data-toggle' => 'pop

我正在尝试实现一个按钮,该按钮显示一个引导弹出窗口,单击该窗口时会显示一个文本字段,用户可以键入他们想要与之共享帖子的人的电子邮件地址
以下是迄今为止按钮的代码:

  <%= link_to collab_user_stories_path(@post), class: 'btn btn-default', title: 'Enter the email of the person you want to share this with:', 'data-toggle' => 'popover', 'data-trigger' => 'focus', 'data-html' => 'true', 'data-content' => '<%= text_field_tag :user %>' do %>
    <span class="glyphicon glyphicon-plus-sign"></span>&nbsp;Collaborate with...
  <% end %>
'popover','data trigger'=>'focus','data html'=>'true','data content'=>'do%>
与…合作。。。

我在
'data-content'=>'
部分中遇到一个错误。
它说:“意外的关键字\u end,expecting')”

我尝试了
'data-content'=>'#{}'
但仍然得到了相同的错误。

有人知道怎么做吗


非常感谢你的帮助

您的第一行应该是:

<%= link_to collab_user_stories_path(@post), 
      title: 'Enter the email of the person you want to share this with:', 
      'data-toggle' => 'popover', 
      'data-trigger' => 'focus', 
      'data-html' => 'true', 
      'data-content' => text_field_tag( :user ),
      class: 'btn btn-default', do %>
“popover”,
“数据触发器”=>“焦点”,
“数据html”=>“true”,
“数据内容”=>text\u field\u标记(:user),
类别:“btn btn默认”,do%>
照目前的情况,您试图在erb中嵌入erb标记,这是行不通的


此外,您还可以尝试将class:'btn btn default',作为链接标记中的最终哈希键/值。

当您添加
数据内容时,您已经在使用ruby代码了,因此您不需要另一组
,您已经在其中了

您需要这样做:

<%= link_to (...) 'data-content' => text_field_tag(:user) do %>
因此,您也不应该在模板中的ruby代码中这样做。


<%= link_to collab_user_stories_path(@post), class: 'btn btn-default', title: 'Enter the email of the person you want to share this with:', data: { toggle: "popover", trigger: "focus", html: "true", content: text_field_tag(:user) } do %>
    <%= content_tag :span, "Collaborate with...", class: "glyphicon glyphicon-plus-sign" %>
<% end %>

由于您使用的是
erb
,因此不需要重新解析
text\u field\u tag
,而只需将其作为
link\u to
方法的参数。您还需要注意,应该将作为哈希传递。

您不能使用
“{}”
,而应该使用
“{}”
。当字符串中有要求值的变量时,请使用双引号。@HassanAkram,您不需要任何双引号,因为您已经在Ruby代码中了。
text\u field\u标记(:user)
就足够了。试图同时使用字符串插值和erb输出肯定行不通。@DaveNewton是的,你完全正确。我刚才在纠正他的台词。{}{code>。啊,你的第一个答案对我最有效!具有
'data-content'=>“{text\u field\u tag(:user)}”
。非常感谢!
<%= link_to collab_user_stories_path(@post), class: 'btn btn-default', title: 'Enter the email of the person you want to share this with:', data: { toggle: "popover", trigger: "focus", html: "true", content: text_field_tag(:user) } do %>
    <%= content_tag :span, "Collaborate with...", class: "glyphicon glyphicon-plus-sign" %>
<% end %>