I am new to ROR and I'm trying hard to solve the issue by going through all the stackoverflow and github pages, I promise I have gone through all of them but still couldn't find a solution to my problem. I hope you guys will help me out.
The issue is that after I implemented thumbs_up gem, I followed the instructions by Brady here: Clarification on how to use "thumbs_up" voting gem with Rails 3
But my view page will have an error message:
No route matches {:action=>"vote_up", :controller=>"posts", :id=>nil}
I have checked rake routes and the vote_up_post path is there, so I tried going to
http://0.0.0.0:3000/posts/vote_up and this shows up:
ActiveRecord::RecordNotFound in PostsController#show
Couldn't find Post with id=vote_up
Here is my views - index.html.erb
<%= link_to('vote for this post!', vote_up_post_path(@post), :method => :post) %>
posts_controller.rb
def vote_up
begin
current_user.vote_for(@post = Post.find(params[:id]))
render :nothing => true, :status => 200
rescue ActiveRecord::RecordInvalid
render :nothing => true, :status => 404
end
end
model - user.rb
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
acts_as_voter
model - post.rb
attr_accessible :title, :source, :description, :imageurl, :link
validates :title, presence: true, uniqueness:true, length: { maximum: 70 }
validates :source, presence: true, length: { maximum: 20 }
validates :description, presence: true, length: { maximum: 240 }
validates :imageurl, presence: true
validates :link, presence: true
default_scope order: 'posts.created_at DESC'
acts_as_voteable
routes.rb
devise_for :users
resources :posts do
member do
post :vote_up
end
end
devise_scope :user do
get "sign_in", :to => "devise/sessions#new"
get "sign_out", :to => "devise/sessions#destroy"
get "sign_up", :to => "devise/registrations#new"
end
resources :submissions
match '/submit', to: 'submissions#new'
match '/post', to: 'posts#new'
Sorry for asking such a stupid problem, would really appreciate help from you guys.
<%= post.title %>
<%= post.source %>
<%= post.description %>
<%= link_to('vote for this post!', vote_up_post_path(@post), :method => :post) %>