'act_as_votable gem giving rotues error No route matches [GET] "/inquests/43/like"
i'm using act_as_votable gem to like inquest , It's giving routes error.i've checked through console it's working fine.here is the same question I tried that solution but it didn't work for me Why isn't my acts as votable working?
def upvote
@inquests = Inquest.find(params[:id])
@inquests.upvote_by current_user
respond_to do |format|
format.html { redirect_to :back}
format.json { head :no_content }
end
end
def downvote
@inquests = Inquest.find(params[:id])
@inquests.downvote_by current_user
respond_to do |format|
format.html { redirect_to :back}
format.json { head :no_content }
end
end
routes.rb
Rails.application.routes.draw do
devise_for :users
resources :inquests do
member do
put "like", to: "inquests#upvote" # maybe change it to POSTS??
put "dislike", to: "inquests#downvote" # maybe change it to POSTS??
end
resources :comments
end
resources :courses
root to: "home#index",as:"profile"
end
user.rb
class User < ApplicationRecord
acts_as_voter
has_many :inquests,dependent: :destroy
has_many :comments,dependent: :destroy
end
inquest.rb
class Inquest < ApplicationRecord
acts_as_votable
belongs_to :user
has_many :comments, -> {order(:created_at => :desc)}, dependent: :destroy
has_many_attached :images
validates :description, presence: true, length: { maximum: 500}
validates :title, presence: true, length: { maximum: 50}
end
inquest_index.html.erb
<div class="vote-rv">
<%= link_to like_inquest_path(inquest), method: :put ,remote: true do %>
<div class="engagement">
<%= button_to "like" %>
<p><%= inquest.get_upvotes.size %> </p>
</div>
<% end %>
<%= link_to dislike_inquest_path(inquest), method: :put,remote: true do %>
<div class="engagement">
<%= button_to "unlike" %>
<p><%= inquest.get_downvotes.size %> </p>
</div>
<% end %>
here is what I get when I like
No route matches [GET] "/inquests/43/like"
Rails.root: /Users/zunairaihsan/Desktop/fyp_ed_bolt
Application Trace | Framework Trace | Full Trace
Routes
Routes match in priority from top to bottom
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
