繁体   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