在路径Rails中传递参数

时间:2018-06-22 13:38:40

标签: ruby-on-rails path modal-dialog bootstrap-modal link-to

我有一个模态,我需要在user_link_path中放入一些数据:

DATA = <div id="modal-myvalue"></div> //DATA
  

DATA = #<UserLink:0x000055635d4d92a0>

<%= link_to "Delete link", user_link_path(NEED TO PUT THE DATA HERE), class: "btn"%>

编辑, 代码:

<button type="button" 
    class="delete-link fa fa-trash" 
    data-toggle="modal" 
    data-target="#confirmation" 
    data-linkname="<%=userlink.link.name.truncate(30)%>" 
    data-myvalue="<%=userlink%>">
</button>

模式:

    <div class="modal fade" id="confirmation" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title" id="myModalLabel">Sure to delete this link :  <div id="modal-linkname"></div></h4>
          </div>
          <div class="modal-body">
            <span id="modal-myvalue"></span> <span id="modal-myvar"></span> <span id="modal-bb"></span>
          </div>
          <div class="body__modal-footer">
           <%= link_to "Delete link", user_link_path(NEED TO PUT THE DATA HERE), class: "btn"%>

                  <button type="button" class="btn btn-outline-secondary btn-sm" data-dismiss="modal">Fermer</button>
                </div>
        </div>
      </div>
    </div>

还有我的Js:

<script>
var ATTRIBUTES = ['linkname', 'myvar', 'bb'];

$('[data-toggle="modal"]').on('click', function (e) {
  var $target = $(e.target);
  var modalSelector = $target.data('target');

  ATTRIBUTES.forEach(function (attributeName) {
    var $modalAttribute = $(modalSelector + ' #modal-' + attributeName);
    var dataValue = $target.data(attributeName);

    $modalAttribute.text(dataValue || '');
  });
});</script>

谢谢

0 个答案:

没有答案