2015-06-20 24 views
2

产生的错误,我有我的看法如下代码:的Rails的link_to在页面加载

<% if @user.marine? %> 
    <div> 
    <%= link_to("Close account".html_safe, deactivate_path(@user), method: :patch, 
     html_options = { role: "button", class: "button-small", data: "Are you certain?" 
     }) %> 
    </div> 
<% end %> 

在开发服务器上加载页面,这会产生下面的错误,指的是<% end %>线。

语法错误,意想不到 ')',期望=>}) ); @ output_buffer.safe_append =
语法错误,意想不到 keyword_end,期望 ')'” .freeze; end

任何人都知道在链接代码中导致错误的原因以及我应该如何调整它?

我认为它与data: "Are you certain?"部分有关。这应该弹出确认消息。我也试过confirm: "Are you certain?",但这没有什么区别。

更新:我不能让链接工作,除非我删除整个html_options部分。只删除data: "Are you certain?"部分是不够的。

回答

3

它是一个散列键,应该有:=>而不是=。试试以下,把所有html_options在一个哈希这样的:

<%= link_to 'Close account'.html_safe, 
       deactivate_path(@user), 
       { method: :patch, role: 'button', class: 'button-small', data: { confirm: 'Are you certain?'} } %> 
+1

是的,它的工作。简单地改为'html_options:'是不够的。因此需要应用您提供的示例。 – Nick

+0

只有确认弹出窗口不起作用。它只是立即删除帐户而不要求确认。你会知道为什么吗?我也试着'确认:'你确定吗?'但这没有什么区别。 – Nick

+1

谢谢,那也工作得很好。 – Nick