简单的锚标记在rails中进行双GET请求

时间:2013-11-22 02:37:30

标签: html ruby-on-rails get anchor

我有一个奇怪的问题,其他一些双重请求问题未能回答。我有一个超级简单的应用程序,基本上是一本漫画书。每当我点击链接转到第二页时,我的服务器都会记录两个GET请求。我不记得这总是发生。可能导致重复GET请求的任何想法?

的routes.rb

root to: 'episodes#index'
resources :episodes, :only => [:index]
post 'pusher/auth'
match '/episodes/:page', to: 'episodes#index', via: 'get'

INDEX.HTML.ERB

<a id="ep-link-2" href="/episodes/2">&nbsp2&nbsp</a>

EPISODESCONTROLLER.RB

def index
    @current_episode = params[:page].to_i || 1

    ep_folder = Dir.new("app/assets/images/episodes")
    #returns 0 if folder name is not a number, meaning it's not an actual episode
    ep_folder = ep_folder.reject { |file| file.to_i == 0 }

    @total_episodes = ep_folder.count

    ip = request.remote_ip
    Visitor.has_visited?(ip)

    total_site_visits = Visitor.total_site_visits
    total_uniques = Visitor.total_uniques

    data = {:total_site_visits => total_site_visits,
           :unique_visits => total_uniques }

    @visit_counts = [total_uniques, total_site_visits]


    Pusher['connections'].trigger('new_connection', data)

    @visitor_data = { :total_site_visits => total_site_visits,
                      :unique_visits => total_uniques }


    respond_to do |format|
      format.html { render :index }
      format.json { render :json => @visitor_data }
    end
  end

1 个答案:

答案 0 :(得分:1)

Kombo建议查看Turbolinks。我添加了data-no-turbolink attr并且双重请求停止了。