[英]Ruby on Rails - Partial not rendering link on creation
大家好,我正在學習Rails並遇到了一個有趣的問題
我有這個偏。
_access_point.html.erb
<div class="card">
<div class="card-body">
<div class="card-title">
<h3 class="text-center"><%= link_to_unless_current access_point.model.upcase, [access_point] %><%= link_to [:edit, access_point], remote: true, class: 'float-right' do fa_icon 'edit lg' end %></h3>
</div>
<div class="card-text">
<p><strong>Manufacturer: </strong><%= access_point.manufacturer %></p>
<p><strong>Serial number: </strong><%= access_point.serial_number %></p>
<p><strong>USER: </strong><%= access_point.user %></p>
<p><strong>PASSWORD: </strong><%= access_point.password %></p>
</div>
</div>
</div>
create.js.erb
$('#access-points-cards').append('<%= j render partial: 'access_point', locals: { access_point: @access_point }, layout: 'layouts/col-md-4' %>')
$('#new-access-point').modal('hide')
我使用的是模態形式,帶有remote:true來創建它,在插入EDIT按鈕后沒有在瀏覽器中顯示,但是在dev工具中顯示,如果我按F5鍵,則一切正常,不要知道它是否存在turbolinks問題或類似問題。
你能幫助我嗎?
您的問題應該是視圖未在DOM中正確更新。 因此,請不要嘗試附加以下內容:
access_point
視圖 使用以下方法將您的局部變量隱藏:
access_point.html.erb : <div class="card hidden">
some_css_file : hidden { display: none }
在JS調用create.js.erb上顯示部分內容
$('.card').show() $('#new-access-point').modal('hide')
決定在何處放置$('.card').hide()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.