【发布时间】:2015-08-31 11:19:27
【问题描述】:
我无法弄清楚为什么我的应用程序无法正常工作。
我有以下routes.rb:
Rails.application.routes.draw do
root to: 'visitors#index'
# ... other routes
# Default root
get '*path', to: "error#error_404"
end
我在浏览器 url 中输入 http://localhost:3000 并被重定向到 http://localhost:3000/404。日志告诉我一件事:
Started GET "/404" for 127.0.0.1 at 2015-08-31 14:24:50 +0300
Processing by ErrorController#error_404 as HTML
Parameters: {"path"=>"404"}
Rendered error/error_404.html.slim within layouts/application (0.8ms)
Rendered layouts/_navigation_links.html.slim (2.2ms)
Rendered layouts/_navigation.html.slim (3.2ms)
Rendered layouts/_messages.html.slim (0.1ms)
Rendered layouts/_footer.html.slim (0.1ms)
Completed 200 OK in 876ms (Views: 875.3ms | ActiveRecord: 0.0ms)
其他相关文件如下:
visitors_controller.rb
class VisitorsController < ApplicationController
def index
@specializations = Specialization.order(name: :asc)
end
...
视图/访问者/index.html.slim
- if @specializations.count == 0
h3.bg-primary.text-center = I18n.t('layout.no_specializations')
- @specializations.each_with_index do |specialization, index|
- if index % 3 == 0
.row
.col-sm-4
= link_to specialization
img src="#{specialization.avatar.url(:thumb)}" /
p.text-center
= specialization.name
- if index % 3 == 2
这可能是什么问题?
附:当我输入例如localhost:3000/specializations/1 时,结果页面会正常加载。
更新
curl localhost:3000 获得正确的 HTML,无需任何重定向。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 routing