如何防止acts_as_votable重定向或刷新? (Rails gem)

时间:2016-04-14 12:23:09

标签: ruby-on-rails url-redirection acts-as-votable

我只是设置了acts_as_votable及其正常工作,但问题是它重定向到帖子的链接以及我添加时

redirect_to :back

刷新页面。

添加代码

这里是route.rb

Rails.application.routes.draw do
  #root 'pages#index'
  resources :posts

  devise_for :users
  # Define root URL
  root 'pages#index'

  # Define roots for pages
  get '/home' => 'pages#home'

  get '/user/:id' => 'pages#profile'

  get '/explore' => 'pages#explore'

  resources :posts do
    member do
      put "like", to: "posts#upvote"  # maybe change it to POSTS??
      put "dislike", to: "posts#downvote" # maybe change it to POSTS??
    end
    resources :comments
  end
######and post_cotroller.rb


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

  def downvote
  @post = Post.find(params[:id])
  @post.downvote_by current_user
  redirect_to :back
  end
##########and index

<%= link_to like_post_path(post), method: :put, class: 'upvote' do %>
                    Upvote
                    <%= post.get_upvotes.size %>
                <% end %>

                <%= link_to dislike_post_path(post), method: :put, class: 'downvote' do %>
                    Downvote
                    <%= post.get_downvotes.size %>
                <% end %>

0 个答案:

没有答案