Rails 如何指定子目录里边的 controller 的路由?

ziu · 2014年04月06日 · 最后由 ziu 回复于 2014年04月06日 · 2841 次阅读

controller 路径 /app/controllers/amount/amount_controller

#routes.rb
 devise_for :users
 root to: "home#index"
  namespace :amount do
    match '/', to: 'amount#index',    via: 'get'
  end

#/app/controllers/amount/amount_controller.rb
class AmountController < ApplicationController
  def index
    debugger
    @user=current_user
  end
end

`rake routes`
 #  root GET    /                              home#index
 #  amount GET    /amount(.:format)              amount/amount#index

然后请求http://0.0.0.0:3000/amount,出现Unable to autoload constant Amount::AmountController, expected /home/fan/rails/Bank/app/controllers/amount/amount_controller.rb to define it, 刷新后是这个错误Circular dependency detected while autoloading constant Amount::AmountController 如何解决?还有请问子目录下面的 controller 要怎么指定路由?使用namespace? 谢谢

class Amount::AmountController < ApplicationController

#1 楼 @themorecolor 谢谢,这样确实可以,但会到amount/amount/下面寻找 template,如何让它在amount/下寻找?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号