레일 4 프로젝트를 작업 중이며 컨트롤러에서 js.erb로 데이터를 전송하는 레일 Ajax 메서드를 사용하고 있습니다.이 작업은 정상적으로 수행되었습니다. 내가 잠시 동안 모든 js.erb 자바 스크립트가 작동을 멈추었지만 서버에서 파일을 보았을 때 요청은 js
으로 보내졌고 제대로 렌더링됩니다. 응답의모든 js.erb가 실행되지만 레일에서 실행되지 않습니다. 4
하나 :
Started GET "/comments/new?comment%5Bcommentable_id%5D=26&comment%5Bcommentable_type%5D=Question" for 127.0.0.1 at 2016-08-21 13:11:32 +0100
Processing by CommentsController#new as JS
Parameters: {"comment"=>{"commentable_id"=>"26", "commentable_type"=>"Question"}}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 20 ORDER BY "users"."id" ASC LIMIT 1
(0.2ms) BEGIN
SQL (0.3ms) UPDATE "users" SET "last_requested_at" = $1, "updated_at" = $2 WHERE "users"."id" = 20 [["last_requested_at", Sun, 21 Aug 2016 12:11:32 UTC +00:00], ["updated_at", Sun, 21 Aug 2016 12:11:32 UTC +00:00]]
(1.3ms) COMMIT
User Load (1.0ms) Select users.* from users, user_categories where user_categories.user_id = users.id and user_categories.category_id in (select user_categories.category_id from user_categories where user_categories.user_id = 20) and users.id not in (20) and users.id not in (SELECT users.id FROM users INNER JOIN relationships ON users.id = relationships.followed_id and relationships.follower_id = 20) group by users.id limit 5
Rendered comments/_form.html.erb (0.8ms)
Rendered comments/new.js.erb (2.0ms)
Completed 200 OK in 12ms (Views: 3.6ms | ActiveRecord: 3.3ms)
이 모든 응용 프로그램 js.erb 파일에 happends하지만 자산에서 모든 스크립트 (vanilar, 커피, JQuery와) 작품 파일 찾기. 나는 지금 몇 달 동안 디버깅을 해왔고, 무엇이 잘못되었는지는 잘 알 수 없었다.
크롬을 검사 할 때 js로 200 응답을 얻었지만 실행이 없으면 다른 브라우저를 사용해 보았습니다. 여기
여기<% if @comment.commentable_type == "Question" %>
$('#comment-form').append('<%= escape_javascript render("form") %>');
$('.comment_link').hide();
<% else %>
$('#comment-form_<%= @comment.commentable_id %>').append('<%= escape_javascript render("form") %>');
$('.comment_link').hide();
<% end %>
$('.cancel-comment').click(function() {
$('#new_comment, .comment-form').hide();
$('.comment_link').show();
})
new.js.erb 새로운 의견이다의가 아약스 requestion 발사 호출하는 링크입니다 :
<%= link_to " Add a comment", new_comment_path(:comment => { :commentable_type => @question.class.name,
:commentable_id => @question.id}),
:remote => true,
:class => "comment_link",
id:"comment_link" %>
컨트롤러 방법 :
은def new
@comment = Comment.new(comment_params)
respond_to do |format|
format.js { render layout: false }
end
end
이전에 작업 했습니까? 보기 파일 .js에 확장을 추가 했습니까? 독립형으로 열 때 파일 내용은 무엇입니까? –
데이터를 추가하기위한 적절한 'DOM'요소를 선택하셨습니까? – uzaif
@JamesTan 예, 그들은 모두 제대로 작동하고있었습니다. 이것은 현재 다른 모든 .js.erb 파일에서도 작동하지 않습니다. js 경고도 거기에서 작동하지 않습니다. uzaif 예, 모든 종류의 javascript 메소드가 실행되지 않는 것 외에 Dom을 매우 잘 선택하고 있습니다. –