Reputation: 1352
issue as above, unable to get "like" button working, posted changes as follows. Thank you in advance. I have modified the routes, models views, controllers as follows.
Acts as Votable Migration
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
Routes=
resources :users do
resources :posts do
member do
post :like
end
resources :comments
end
end
Models
(User)has_many :posts
(Post)has_many :comments
(Post)belongs_to :user
(Comment)belongs_to :post
Controller(posts)
def like
@post= Post.find(params[:id])
@post.liked_by current_user
redirect_to :back
flash[:notice]="Liked!"
end
Index(posts)
<%= 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 %>
Upvotes: 0
Views: 712
Reputation: 1548
If you want to make nice voting system you can use these gems
https://github.com/bouchard/thumbs_up
https://github.com/twitter/activerecord-reputation-system
I am using thumbs_up on my app and its working great
Upvotes: 1