Rails No Routes匹配url

时间:2013-09-22 21:19:58

标签: ruby-on-rails routes

所以我的路线是:

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

1 个答案:

答案 0 :(得分:0)

我的一位朋友(@readingr_uk)告诉我如何解决这个问题。我将路由从使用:username更改为using:id

match '/user/:id/' => 'user/account/home#index', via: [ :get ], as: :user_view, constraints: UserConstraint