【问题标题】:Ruby on Rails - Partial not rendering link on creationRuby on Rails - 创建时部分未呈现链接
【发布时间】:2018-11-08 14:15:57
【问题描述】:

各位,我正在学习 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 按钮后不会显示在浏览器中,但会显示在开发工具中,如果我按 F5 则显示一切正常,不知道是turbolinks问题还是类似的问题。

你能帮帮我吗?

【问题讨论】:

  • 那么_access_point部分根本没有渲染或者渲染后有一些问题?
  • 正常渲染。 &lt;h3 class="text-center"&gt;&lt;%= link_to_unless_current access_point.model.upcase, [access_point] %&gt;&lt;%= link_to [:edit, access_point], remote: true, class: 'float-right' do fa_icon 'edit lg' end %&gt;&lt;/h3&gt; 在这部分部分中,link_to_unless_current 工作正常,但 fa_icon 不显示

标签: javascript ruby-on-rails ruby ruby-on-rails-5


【解决方案1】:

您的问题应该是视图没有在 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()

【讨论】:

    猜你喜欢
    • 2014-10-28
    • 2011-01-08
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 2011-05-11
    相关资源
    最近更新 更多