2011-06-14 5 views
0

Ruby on Rails 튜토리얼에서 작업 중입니다. 비동기 추적 단추가 작동합니다. 흥미롭게도 버튼을 클릭하면 각 자바 스크립트 호출이 두 번 연속 호출됩니다. 내가 어떻게 만들어야하는지에 대한 생각은 오직 하나의 요청만을 보낸다. 여기 여기 JS 요청이 두 번 연속 호출 됨

Started POST "/tag_user_relationships/123" for 
127.0.0.1 at 2011-06-13 21:18:59 -0700 Processing by TagUserRelationshipsController#destroy as JS Parameters: {"utf8"=>"✓", "authenticity_token"=>"goedvibRxKtDRiAufp1ThWJP0rRBU2cMH2xp7qodKws=", "commit"=>"Unfollow", "id"=>"123"} User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1 TagUserRelationship Load (0.2ms) SELECT `tag_user_relationships`.* FROM `tag_user_relationships` WHERE `tag_user_relationships`.`id` = 123 LIMIT 1 Tag Load (0.2ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`id` 
= 9 LIMIT 1 TagUserRelationship Load (0.3ms) SELECT `tag_user_relationships`.* FROM `tag_user_relationships` WHERE `tag_user_relationships`.`tag_id` = 9 AND (`tag_user_relationships`.user_id 
= 2) LIMIT 1 SQL (0.1ms) BEGIN AREL (0.2ms) DELETE FROM `tag_user_relationships` WHERE `tag_user_relationships`.`id` = 123 SQL (0.4ms) COMMIT SQL (0.4ms) SELECT COUNT(*) FROM `users` INNER JOIN `tag_user_relationships` ON `users`.id = `tag_user_relationships`.user_id WHERE ((`tag_user_relationships`.tag_id = 9)) SQL (0.3ms) SELECT COUNT(*) FROM `tags` INNER JOIN `tag_user_relationships` ON `tags`.id 
= `tag_user_relationships`.tag_id WHERE ((`tag_user_relationships`.user_id = 2)) Rendered tag_user_relationships/_form.js.erb (15.8ms) Rendered tags/_follow.html.erb (2.1ms) Rendered tag_user_relationships/destroy.js.erb (20.3ms) Completed 200 OK in 138ms (Views: 28.1ms | ActiveRecord: 2.3ms) 


Started POST "/tag_user_relationships/123" for 
127.0.0.1 at 2011-06-13 21:18:59 -0700 Processing by TagUserRelationshipsController#destroy as JS Parameters: {"utf8"=>"✓", "authenticity_token"=>"goedvibRxKtDRiAufp1ThWJP0rRBU2cMH2xp7qodKws=", "id"=>"123"} User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1 TagUserRelationship Load (0.2ms) SELECT `tag_user_relationships`.* FROM `tag_user_relationships` WHERE `tag_user_relationships`.`id` = 123 LIMIT 1 Completed 404 Not Found in 70ms 

ActiveRecord::RecordNotFound (Couldn't find TagUserRelationship with ID=123): app/controllers/tag_user_relationships_controller.rb:14:in `destroy' 

Rendered /Users/me/.rvm/gems/[email protected]/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms) Rendered /Users/me/.rvm/gems/[email protected]/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (153.6ms) Rendered /Users/me/.rvm/gems/[email protected]/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (160.2ms) 

그리고 내 로그

것은 내보기

$("#<%= "follower_info#{@tag.id}" %>").html("<%=escape_javascript(pluralize(@tag.followers.count,'follower'))%>");  
var link = $('<a>').attr('href',"<%=user_tags_path(current_user) %>").text("<%= escape_javascript(pluralize(current_user.beats.count,'tag')) %>"); 
$("#<%= "user#{current_user.id}_following" %>").html(link); $("#<%= "follow_form#{@tag.id}" %>").html("<%= escape_javascript("#{render('tags/unfollow', :tag => @tag)}").html_safe %>"); 

그리고 내 컨트롤러

def create 
    @tag = Tag.find(params[:tag_user_relationship][:tag_id]) 
    current_user.follow_tag!(@tag) 
    respond_to do |format| 
     format.html { redirect_to @tag } 
     format.js 
    end 
    end 

답변

4

나는 최근이 같은 문제를 가지고있다. Javascript 폴더에 jQuery 코드가 포함되어있을 가능성이 있습니까? 그렇다면 통화가 두 번 이루어집니다.

+0

저는 아약스 보석을 설치했다고 생각하지 않습니다. gemfile에 추가 했습니까? 나는 jquery 코드를 가지고있다. – Cyrus

+0

javascripys 폴더에 jquery 코드를 두 번 포함 할 가능성이 있습니까? – cmwright

+0

빙고 - jquery.min 및 jquery_ujs가 있습니다. – Cyrus