所以我的路线是:
match '/user/:username/' => 'user/account/home#index', via: [ :get ], as: :user_view, constraints: UserConstraint
控制器的代码是:
class User::Account::HomeController < User::ApplicationController
def index
@account = User.find_by_username(params[:username])
end
end
但是,当我调用该 url(即http://example.com/user/xerax)时,这是 rails 向我抛出的错误:
No route matches {:controller=>"user/account/home", :username=>nil}
编辑:我正在使用 Rails 3.2.13