我有一个奇怪的问题,其他一些双重请求问题未能回答。我有一个超级简单的应用程序,基本上是一本漫画书。每当我点击链接转到第二页时,我的服务器都会记录两个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"> 2 </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
答案 0 :(得分:1)
Kombo建议查看Turbolinks。我添加了data-no-turbolink attr并且双重请求停止了。