我有一个使用标准rails new
命令创建的rails站点,然后是rails g controller [page] [index file]
命令,以便为每个新页面提供视图和控制器。但是,无论何时我在链接上多次单击,或者在页面加载之前单击链接后快速跟随不同的链接,我都会得到一个double / treble / etc路由;例如以下内容:
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)。 routes文件如下所示:
# 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
有什么想法吗?
答案 0 :(得分:0)
所以,这里有很多内容。
首先,每个进入你的路线的人都会寻找一个同名的控制器。你只有1,这就是为什么它找不到它。如果所有这些都是您要查看的模型,则需要为每个模型制作一个控制器(以及每个控制器的模型)。这里有很多错误,所以你没有输入一个5段的解释,而是关注rails的教程,或者只是自己罢工并试图弄清楚要做什么?