1

我已经像这样配置了acts_as_votable,以在我的应用程序中生成内容的赞成和反对:

部分的:

<div class="btn-group">
        <%= link_to like_link_path(link), method: :put, class: "btn btn-success btn-sm" do %>
          <span class="glyphicon glyphicon-chevron-up"></span>
          Upvote
          <%= link.get_upvotes.size %>
        <% end %>
        <%= link_to dislike_link_path(link), method: :put, class: "btn btn-warning btn-sm" do %>
          <span class="glyphicon glyphicon-chevron-down">
          Downvote
          <%= link.get_downvotes.size %>
        <% end %>
    </div>

控制器:

  def upvote
    @link = Link.find(params[:id])
    @link.upvote_by current_user
    redirect_to :back
  end

  def downvote
    @link = Link.find(params[:id])
    @link.downvote_from current_user
    redirect_to :back
  end

路线:

resources :links do
    member do
      put "like", to: "links#upvote"
      put "dislike", to: "links#downvote"
    end
  end

尽管我在路由和视图中都非法调用了 put 请求,但我的日志显示我的浏览器正在尝试发出 get 请求:

Jan 12 16:43:24 quotesappp app/web.1:  Started GET "/links/1/dislike" for 96.248.110.224 at 2016-01-13 00:43:23 +0000

以前我在本地测试时这不是问题,但是在部署到 Heroku 时,它没有注册 put 请求。谁能看到我做错了什么?

4

0 回答 0