2015-06-20 23 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