2017-04-06 47 views
0

我正在研究與Dropbox具有相似功能的Ruby on Rails項目。寶石使用:使用引導模式呈現編輯部分表單

  1. carrierwave:上傳文件
  2. acts_as_tree:文件夾目錄
  3. 苗條:清潔HTML
  4. 引導4

我試圖將引導用於呈現編輯表單的模態,以便用戶能夠編輯我在模型中的file_name屬性。

- @documents.each do |document| 
    = link_to document.file.filename, document.file.url 
    b = document.file_name 
    = number_to_human_size(document.file.size, :precision => 2) 
    = document.content_type 
    = document.updated_at 
    = link_to "Download", document.file.url 
    #renameButton.button.btn.btn-primary data-toggle="modal" data-target="#renameModal" Rename 
    #renameModal.modal.fade tabindex="=1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" 
    .modal-dialog role="document" 
     .modal-content 
     .modal-header 
      #exampleModalLabel.h5.modal-title Rename folder 
      button.close data-dismiss="modal" aria-label="Close" 
      span aria-hidden="true" × 
     .modal-body 
      = form_for document do |f| 
      = f.label :name 
      = f.text_field :file_name 
      = f.submit 
     .modal-footer 
      button.btn.btn-outline-success data-dismiss="modal" aria-hidden="true" Close 
      button.btn.btn-outline-danger Save changes 
    = link_to "Delete", document, :confirm => 'Are you sure?', :method => :delete 

我的問題是,每當我點擊我的任何「重命名」按鈕,模式裏面所呈現的編輯表單總是指向1號文件條目,而不是選擇之一。

我認爲在我的do-loop中有一個模式會導致這個問題。

有沒有辦法解決這個問題?

回答

0

的問題可能是您正在使用相同的data-target爲重命名BUTTOM點擊打開模型,每一個模態具有相同的ID

嘗試使用一個迭代每個ID

data-target="#renameModal#{index}" 

,並與你的模型編號應該是:

id: "#renameModal#{index}" 

我不知道很多關於slim語法使用,所以請使用你的苗條語法。 這只是一個基本的Bootstrap概念。

希望這有助於...

+0

這工作就像一個魅力!非常感謝你mayank! –