0

destroy メソッドに問題があります。私の考えは部分的に再レン​​ダリングすることですが、部分的にチェックを行う必要がありますif @driving_informations.present?。したがって、リンク「削除」ページをクリックしても何もせず、データはページに残っています.F5を押してページをリロードすると、すべて問題ありません-データは存在しません!

これは私のコントローラーメソッドです

def destroy
    @driving_information.destroy
    @user = @driving_information.user
    @driving_informations = @user.driving_informations
    render '_list.html.haml', layout: false
end

と表示

%h4= t("driving_information.driving_info")
-if @driving_informations.present?
  =render ("list")
  -if @user == current_user
    - @driving_informations.each do |driving_information|
      = link_to t('common.edit'), edit_driving_information_path(driving_information), remote: true, data: { toggle: "modal", target: "#ajax-modal" }
      = link_to t('common.delete'), driving_information_path(driving_information), method: :delete, remote: true, data: { confirm: t('common.confirm') }
-else
  = link_to t('common.add'), new_driving_information_path, remote: true, data: { toggle: "modal", target: "#ajax-modal" } if @user == current_user
  %p= t('driving_information.not_exists') if @user != current_user

:javascript
  $(function(){
    $("table.driving-information .destroy-btn").on("ajax:success", function(event, data, status, xhr){
      $('#driving-information-block').html(data);

何か案は?

4

1 に答える 1

0

破棄が成功した場合は、AJAX で jQuery を使用してフォームをターゲットにしてクリアすることをお勧めします。フォーム ID をform次のように仮定します。

#('#form').find("input[type=text], textarea").val("");

出典: jQuery でフォーム フィールドをクリアする

于 2013-11-03T04:11:13.893 に答える