双击我的 Rails 站点上的链接会导致路由不正确



我有一个使用标准rails new命令创建的rails站点,后跟rails g controller [page] [index file]命令来常规每个新页面的视图和控制器。但是,每当我在链接上多次单击时,或者当我在页面加载之前快速单击链接后跟不同的链接时,我都会得到双倍/三倍/等路由;例如:

http://www.alisaesage.com/shaltayboltay/shaltayboltay/index

这显然会导致 404。此路由是从索引页访问的,索引页具有以下模板代码:

<div class="container">
  <div class="header">
    <h1 class="title">AlisaEsage.com</h1>
    <h2 class="master-sub">A Resource</h2>
    <h3 class="mini-sub">Info, forums, articles, resources etc, by, about and related to the Alisa "Esage" Shevchenko, story. The idea is to give a full and complete picture of the "U.S. certified Russian Hacker", her guilt or innocence, her motivations and goals, as well as those of her networks of influence, and any and all of her close associates and 'partners in crime'.</h3>
  </div>
  <div class="list-box-outer">
    <div class="list-box-inner">
      <ul class="list">
        <li><a href="./aboutalisa/index">About Alisa</a></li>
        <li><a href="./shaltayboltay/index">Шалтай Болтай</a></li>
        <li>Operation Silk Scarf</li>
        <li><a href="./articles/index">Media Articles</a></li>
        <li><a href="./social/index">Social Media</a></li>
        <li>Conspiracy Theories</li>
        <li><a href="./phrahacking/index">Hacking/Phracking etc</a></li>
        <li>Forums</li>
        <li>Puppies and Other Animals</li>
        <li><a href="./quotes/index">Quotes</a></li>
        <li><a href="./pics/index">Fashion/Pics</a></li>
        <li><a href="./geopolitics/index">Geopolitics</a></li>
        <li><a href="./fanfic/index">Poetry/Fanfic</a></li>
        <li>Contribute</li>
        <li>Contact</li>
      </ul>
    </div>
  </div>
  <p>Owned and maintained by re8e1d45</p>
</div>

以及以下控制器:

class HomeController < ApplicationController
  def index
  end
end
(是的

,是的。控制器中还没有非常复杂的东西:-P(。路由文件如下所示:

 # Basic Routings
 Rails.application.routes.draw do
  get 'geopolitics/index'
  get 'aboutalisa/index'
  get 'shaltayboltay/index'
  namespace :curious do
    get 'part1/index'
  end
  namespace :curious do
    get 'part2/index'
  end
  get 'part2/index'
  get 'political/index'
  get 'manifestos/index'
  get 'fanfic/index'
  get 'pics/index'
  get 'quotes/index'
  get 'contributions/index'
    get 'phrahacking/index'
    get 'puppies/index'
    get 'social/index'
    get 'articles/index'
    get 'nineteeneightyfour/hidden'
    get 'home/index'
    get '/defaultsite' => 'home#index'
    get '/' => 'home#index'
    resources :articles
  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".
  # You can have the root of your site routed with "root"
  # root 'home#index'
  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'
  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products
  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end
  # Example resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end
  # Example resource route with more complex sub-resources:
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', on: :collection
  #     end
  #   end
  # Example resource route with concerns:
  #   concern :toggleable do
  #     post 'toggle'
  #   end
  #   resources :posts, concerns: :toggleable
  #   resources :photos, concerns: :toggleable
  # Example resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end
end

有什么想法吗?

所以,这里发生了很多事情。

首先,每个进入您的路由的人都将寻找同名的控制器。你只有 1,所以这就是为什么它找不到它。如果所有这些都是你尝试查看的模型,你需要为每个模型创建一个控制器(以及每个模型(。这里还有很多错误,所以你不是打出 5 段的解释,而是遵循 rails 教程还是只是自己努力弄清楚该怎么做?

最新更新