Nice programing

link_to : 확인 팝업이 두 번 표시됨

nicepro 2020. 12. 27. 20:44
반응형

link_to : 확인 팝업이 두 번 표시됨


레일 3이있는이 태그

<%= link_to 'Destroy', item, :method => :delete,:confirm=>'Are you sure?' %>

이 HTML을 생성

<a href="/news/3" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a>

항목이 삭제되고 팝업이 두 번 나타나는 문제가 있습니다.

원인은 무엇입니까?


rails.js의 확인 핸들러 Javascript가 두 번 첨부되는 것 같습니다.

실수로 javascript_include_tag 도우미의 복제를 통해 rails.js의 두 복사본을 포함 할 수 있습니까?


나는 똑같은 문제를 겪고 있었고 한 시간 동안 더 많은 시간을 보냈습니다. 내 상황에서 해결책을 찾았고 도움이 될 경우 공유 할 것이라고 생각했습니다.

내 문제는

config.assets.debug = true 

설정 / 환경 / development.rb

해당 라인을

config.assets.debug = false

나를 위해 확인 중복을 수정했습니다. 자산 파이프 라인대한 레일스 가이드 에서 관련 정보를 찾았습니다 . 도움이 되었기를 바랍니다.


나는 javascript_include_taghaml-layout-file의 맨 아래에 를 포함하는 데 사용되었습니다 .

Rails4 및 Turbolinks를 사용하면 다음과 같은 일이 발생합니다.

  • 페이지를 처음로드 할 때 모든 것이 정상입니다 (확인 팝업은 한 번만 나타남).
  • 다른 페이지 방문-> 팝업이 두 번 발생
  • 한 페이지 더 방문-> 팝업이 세 번 발생
  • 등등
  • 페이지를 새로 고침 할 때까지

javascript_include_tag아래에서 아래로 이동하여 문제를 해결했습니다.<head>


저는 Rails 4를 사용하고 있으며 어떤 답변도 저에게 효과가 없었지만 다음은 효과가있었습니다 ... 라인을 변경했습니다.

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 

...에

<%= javascript_include_tag 'application', 'data-turbolinks-eval' => false %>.

https://github.com/rails/turbolinks/issues/244


여기에 훌륭한 답변,

그러나 모든 작업을 수행했지만 여전히 이중 팝업이 표시되고 개발 모드 에서 실행중인 경우 public/assets컴파일 된 자산 로드 했는지 확인하십시오 .

삭제 public/assets/*하면 문제가 해결됩니다.


이것은 Rails의 버그 인 것 같습니다. 분명히 application.js의 지시문은 디버그 모드가 활성화되면 개별 파일로 확장 될뿐만 아니라 application.js에도 포함됩니다. 나는 이것을 위해 Rails 코드를 보지 않았지만 application.js가 기본 JavaScript 파일이기 때문이라고 가정합니다. 이 파일의 이름을 다른 것으로 바꾸면 default.js는 디버그 모드에서 지시문에 지정된 파일을 올바르게 포함하고 default.js는 해당 파일에만있는 JavaScript 만 출력합니다. 따라서 중복 코드를 생성하지 않습니다.

예:

application.js

// = jquery_ujs 필요

foo ();

결과 :

1) jquery_ujs.js

2) jquery_ujs 내용과 foo ()가있는 application.js


default.js

// = jquery_ujs 필요

foo ();

결과 :

1) jquery_ujs.js

2) foo ()를 사용하는 default.js


Rails 3.2.12에서 동일한 문제가 있었지만 3.2.13으로 업데이트하면 그 문제가 해결되었습니다.


이 솔루션을 다른 게시물에서 복사했지만 이것이 저에게 효과적이었습니다 (rails 5).

"rails_ujs는 최신 rails 버전에 충분하므로 application.js에서 jquery_ujs를 제거하십시오."

나는 포함했다 : //= require jquery //= require jquery-ujs //= require rails-ujs

삭제 후 모두 정상적으로 작동합니다. 해결 방법 : Rails에서 JQuery 경고가 두 번 표시되는 이유는 무엇입니까?


제 경우 (Rails 3.2.13)에서는 동일한 문제를 해결하기 위해 rails.js삭제해야 했습니다.

rails.js를 명시 적으로 참조하지 않았고 config.assets.debug 도움말을 변경하지도 않았습니다.


제 경우에는 jQuery가 라인 때문에 두 번로드되었습니다. //= require_tree .

application.js에서이 오류를 방지하고 내가 하위 디렉토리를 생성하는 데 사용 해요 application.css하려면 app/assets/javascript/autorequire대신의 require_tree .내가 할 require_tree ./autorequire.

So, files in app/assets/javascript and app/assets/stylesheets are not included automatically/accidentally anymore. I put all my individual .css and .js files into the subdirectory and they are included implicitly. But I can define which files from the top-path are to be included and in which order.

Since I do so, I never had troubles by assets not loaded as I expect them to be.


So for me it was because i had defined data-remote instead of just remote.

IE

data: { remote: true, ... }

instead of

remote: true, data: { ... }

hope that helps.


In my case, it was that the application had both "mootools ujs" and "jquery ujs" included. I got rid of the mootools one and now I only see one confirmation.


just remove the turbolinks, that worked for me in rails4


Try to run either

rake assets:precompile ENV=development 

or

rake assets:precompile ENV=production

Delete:

//= require jquery
//= require jquery_ujs
//= require_tree .

from app/assets/javascripts/application.js. Despite of been commented it loads these js files. It works for me.

ReferenceURL : https://stackoverflow.com/questions/4475449/link-to-confirm-displays-popup-twice

반응형