我想使用acts_as_follower gem(link)與ajax,如here所述。我有的問題是,它遵循/取消關注,但沒有ajax(你必須按順序刷新頁面看到按鈕上的變化)acts_as_follower與ajax不起作用
這裏是我的代碼:
user.rb,create.js.erb,destroy.js.erb,_follow_user.html.erb,show.html.erb是就像第二個鏈接一樣,routes,users_controller和following_controller如下:
users_controller.rb
def show
@user = User.find_by_username(params[:id])
@description = Description.new
@descriptions = Description.where(:user_id => @user.id).order("created_at desc")
end
的routes.rb
resources :users, :path => '', :only => [:show] do
resources :follows, :only => [:create, :destroy]
end
follows_controller.rb
def create
@user = User.find_by_username(params[:user_id])
current_user.follow(@user)
end
def destroy
@user = User.find_by_username(params[:user_id])
current_user.stop_following(@user)
end
什麼在你嵌入_follow_user.html.erb局部的看法?該示例中的create.js.erb和destroy.js.erb假定頁面上存在一個#follow_user元素,該元素包裝_follow_user.html.erb部分。您的示例可能會有所不同或更復雜(例如,每頁有多個)。你能提供一些關於你的觀點的更多細節嗎? –