Rails app将根请求重定向到/ 404

时间:2015-08-31 11:19:28

标签: ruby-on-rails ruby-on-rails-4 routing

我无法弄清楚为什么我的应用程序无法正常运行。

我有以下routes.rb

Rails.application.routes.draw do

  root to: 'visitors#index'

  # ... other routes

  # Default root
  get '*path', to: "error#error_404"

end

我在浏览器网址中输入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

这里有什么问题?

P.S。当我输入e,g,localhost:3000/specializations/1时,生成的页面会正常加载。

更新

curl localhost:3000获取正确的HTML,无需任何重定向。

1 个答案:

答案 0 :(得分:0)

原来是糟糕的代码。这一行:

public class DefaultHeading extends FrameLayout { public DefaultHeading(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.awesomeedit, 0, 0); String name; String regex; String hint; String error; String link; try { name = ta.getString(R.styleable.awesomeedit_name); regex = ta.getString(R.styleable.awesomeedit_regex); hint = ta.getString(R.styleable.awesomeedit_hint); error = ta.getString(R.styleable.awesomeedit_error); link = ta.getString(R.styleable.awesomeedit_link); required = ta.getBoolean(R.styleable.awesomeedit_required, false); email = ta.getBoolean(R.styleable.awesomeedit_email, false); password = ta.getBoolean(R.styleable.awesomeedit_password, false); nummber = ta.getBoolean(R.styleable.awesomeedit_number, false); } finally { ta.recycle(); } LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = mInflater.inflate(R.layout.default_heading, this, true); addView(view); }

应该重构为

img src="#{specialization.avatar.url(:thumb)}" /

完成。的工作原理。