我有一個rails鏈接,我想把它添加到一個下拉選單中,但它表現得很奇怪,我無法找出原因。
我粘貼了下面的代碼塊:
<%= link_to edit_profile_post_path(article.profile, article. post), :class => "dropdown-item" if article.post.present? do %>
<div class="flex" >
< div class="w-5 mr-2flex items-center justify-center" >
< i class="text-inherit fal icon-sm fa-trash-alt" aria-hidden="true"></i>/span>
</div>
編輯帖子
</div>
<% end %>
當我預覽下拉選單時,我看到的是鏈接路徑,而不是 "編輯帖子 "的字樣:
但更令我困惑的是,當我將滑鼠懸停在該鏈接上時,它實際上是:
http://localhost:3000/profiles/gerard-donnelly?class=dropdown-item作業正常的原始代碼是:
<%= link_to 'Edit Post'/span>, edit_profile_post_path(article.profile, article. post), class: 'dropdown-item' if article. post.present?%>。
如果能幫助解決這個問題,我將非常感激。
uj5u.com熱心網友回復:
你把條件放在了呼叫的錯誤一側。如果它是純粹的Ruby,這將看起來像
link_to(path, class: klass') if article. post.present? do.
'content'
結束
do/end塊被傳遞給present?方法,這不是你想要的。相反:
link_to(path, class: 'klass') do
'content'/span>
end if article.post.present?
將作業。翻譯回ERB:
<%= link_to edit_profile_post_path(article.profile, article. post), :class => "dropdown-item" do %>
<div class="flex" >
< div class="w-5 mr-2flex items-center justify-center" >
< i class="text-inherit fal icon-sm fa-trash-alt" aria-hidden="true"></i>/span>
</div>
編輯帖子
</div>
<% end if article.post.present? %>。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/307590.html
標籤:
上一篇:正則運算式(^|[^A-Za-z0-9])Trump([^A-Za-z0-9]|$)意味著
下一篇:以"!"結尾的Ruby方法的含義
