簡體   English   中英

Ruby on Rails-創建時部分不渲染鏈接

[英]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_filehidden { display: none }

  • 在JS調用create.js.erb上顯示部分內容

    $('.card').show() $('#new-access-point').modal('hide')

  • 決定在何處放置$('.card').hide()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM