私はレール4プロジェクトを行っていますが、コントローラからjs.erbにデータを転送するレールAjaxメソッドを使用しています。私はしばらくの間、すべてのjs.erb javascriptが動作を停止したことに気づきましたが、サーバからのファイルを見ると、リクエストは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は)作品は、ファイル検索。私は今何ヶ月もデバッグしていますが、何が間違っているかは分かりませんでした。
フォームクロムを検査しようとしたとき、私は200応答をjsとして取得しましたが、実行していないため、別のブラウザも試しました。ここ
はここ
<% 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新しいコメントであるのは、Ajaxの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ファイルには今は動いていません。 uzaifはい、私は非常によくjavascriptのメソッドのすべての種類の横に実行されていない選択しています。 –