問題如上,無法獲得「喜歡」按鈕的工作,發佈更改如下。先謝謝你。我已經修改了路線,模型視圖,控制器如下。acts_as_votable按鈕不更新
充當可投票遷移
class ActsAsVotableMigration < ActiveRecord::Migration
def self.up
create_table :votes do |t|
t.references :votable, :polymorphic => true
t.references :voter, :polymorphic => true
t.boolean :vote_flag
t.string :vote_scope
t.timestamps
end
add_index :votes, [:votable_id, :votable_type]
add_index :votes, [:voter_id, :voter_type]
add_index :votes, [:voter_id, :voter_type, :vote_scope]
add_index :votes, [:votable_id, :votable_type, :vote_scope]
end
def self.down
drop_table :votes
end
end
路線=
resources :users do
resources :posts do
member do
post :like
end
resources :comments
end
end
模型
(User)has_many :posts
(Post)has_many :comments
(Post)belongs_to :user
(Comment)belongs_to :post
控制器(公告)
def like
@post= Post.find(params[:id])
@post.liked_by current_user
redirect_to :back
flash[:notice]="Liked!"
end
指數(職位)
<%= link_to like_user_post_path(post.user,post), :method => :post ,:class =>"" do%>
<span class="btn btn-primary editlike">
<%=post.likes.size %>
<i class="icon-heart ">
</i></span><%end %>
轉儲的錯誤信息是什麼? –