我一直试图在没有运气的情况下在网上到处找到这个答案,也许这会对其他人有所帮助。
我安装了一个名为 socialization 的 ruby gem,它运行良好。它允许用户关注/取消关注/喜欢/不喜欢/提及任何内容。
我遇到的问题是我已经创建了两个链接(一个跟随和一个取消跟随)链接有效,当单击时,记录会完美地从数据库中添加和删除但是当我点击刷新时,无论如何都会发生操作,而无需我单击链接.
尽可能明确的问题是:
如果当前已关注用户并且我刷新页面,则将取消关注(无需单击按钮)..然后当他们取消关注并刷新页面时,他们现在将再次被关注(再次无需单击按钮)
这是代码:
<% if current_user.follows?(@user)%>
<%= link_to "Unfollow", user_path, :action => current_user.unfollow!(@user), :class => "btn btn-primary"%>
<% else %>
<%= link_to "Follow", user_path, :action => current_user.follow!(@user), :class => "btn btn-primary"%>
<% end %>
我认为这与以下任何一个有关:浏览器缓存链接或生成的链接是
<a href="/users/1" action="#<Follow:0x103ce81d8>" class="btn btn-primary" rel="nofollow">Follow</a>
并且该操作以任何一种方式执行
编辑:
Rake routes:
users_index GET /users/index(.:format) users#index
dashboard_index GET /dashboard/index(.:format) dashboard#index
dashboard_my_rentals GET /dashboard/my_rentals(.:format) dashboard#my_rentals
dashboard_my_credits GET /dashboard/my_credits(.:format) dashboard#my_credits
dashboard_my_invites GET /dashboard/my_invites(.:format) dashboard#my_invites
dashboard_my_faves GET /dashboard/my_faves(.:format) dashboard#my_faves
dashboard_edit_profile GET /dashboard/edit_profile(.:format) dashboard#edit_profile
tsmhome_index GET /tsmhome/index(.:format) tsmhome#index
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
home_index GET /home/index(.:format) home#index
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
/show/:id(.:format) user#show
root / home#index
user controller
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :json => @users }
end
end
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :json => @user }
end
end