[英]Rails link_to generating error on page loading
我認為以下代碼:
<% 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; 結束
任何人都知道鏈接代碼中是什么導致了錯誤,我應該如何調整呢?
我認為這與以下data: "Are you certain?"
部分。 這應該彈出一個確認消息。 我還嘗試confirm: "Are you certain?"
而是沒有什么區別。
更新:除非刪除整個html_options
部分,否則無法使用該鏈接。 只需刪除data: "Are you certain?"
部分還不夠。
它是一個哈希鍵,應該有:
或=>
而不是=
。 嘗試以下操作,將所有html_options
分組為一個散列,如下所示:
<%= link_to 'Close account'.html_safe,
deactivate_path(@user),
{ method: :patch, role: 'button', class: 'button-small', data: { confirm: 'Are you certain?'} } %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.