在按照书中代码编写 follow 和 unfollow 按钮时,添加上 ajax 功能后
点击之后就会出现错误
下面为点 unfollow 点击出现的错误信息
Started DELETE "/relationships/1" for 127.0.0.1 at 2012-10-28 20:53:33 +0800
Processing by RelationshipsController#destroy as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"A5HEZNjXLdmCzAO5BXmPXb3X2VkHs8rDpqrw/zErq0k=", "commit"=>"Unfollow", "id"=>"1"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Rendered users/_unfollow.html.erb (2.2ms)
Rendered relationships/destroy.js.erb (2.9ms)
Completed 500 Internal Server Error in 6ms
ActionView::Template::Error (Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id):
1: <%= form_for(current_user.relationships.find_by_followed_id(@user.id),
2: :html => { :method => :delete },
3: :remote => true) do |f| %>
4: <div class="actions"><%= f.submit "Unfollow" %></div>
app/views/users/_unfollow.html.erb:1:in `_app_views_users__unfollow_html_erb__1917503669697459990_70063164482580'
app/views/relationships/destroy.js.erb:1:in `_app_views_relationships_destroy_js_erb___120623583448683911_70063171541040'
_destroy.js.erb
$("follow_form").update("<%= escape_javascript(render('users/unfollow')) %>")
$("followers").update('<%= "#{@user.followers.count} followers" %>')
查找了好久,找不出解决方法
还有求点 rails 中用 ajax 的资料