问题是如此简单,我不知道可能出了什么问题。
我有这个规格:
it "/fr/admin/articles/new" do
expect(:get => "/fr/admin/articles/new").to route_to(:controller => 'articles', :action => 'new')
end
当我浏览 localhost:3000/fr/admin/articles/new 时,它可以工作!
但我的测试说:
Failure/Error: expect(:get => "/fr/admin/articles/new").to route_to(:controller => 'articles', :action => 'new')
No route matches "/fr/admin/articles/new"
# ./spec/routing/articles_routing_spec.rb:6:in `block (2 levels) in <top (required)>'
我的路线.rb:
scope '/:locale', :constraints => LocaleConstraint do
root :to => 'static#home'
scope '/admin' do
root :to => 'articles#index'
resources :articles
end
end
还有我的 locale_constraint.rb
class LocaleConstraint
def self.matches?(request)
/(fr|zh)/.match(request.path_parameters[:locale])
end
end
rake 路由的输出:
ckeditor /ckeditor Ckeditor::Engine
admin /admin(.:format) :controller#:action
login GET /login(.:format) sessions#new
logout GET /logout(.:format) sessions#destroy
sessions POST /sessions(.:format) sessions#create
root /:locale(.:format) static#home
root /:locale/admin(.:format) articles#index
articles GET /:locale/admin/articles(.:format) articles#index
POST /:locale/admin/articles(.:format) articles#create
new_article GET /:locale/admin/articles/new(.:format) articles#new
edit_article GET /:locale/admin/articles/:id/edit(.:format) articles#edit
article GET /:locale/admin/articles/:id(.:format) articles#show
PUT /:locale/admin/articles/:id(.:format) articles#update
DELETE /:locale/admin/articles/:id(.:format) articles#destroy
root / :controller#:action
Routes for Ckeditor::Engine:
pictures GET /pictures(.:format) ckeditor/pictures#index
POST /pictures(.:format) ckeditor/pictures#create
picture DELETE /pictures/:id(.:format) ckeditor/pictures#destroy
attachment_files GET /attachment_files(.:format) ckeditor/attachment_files#index
POST /attachment_files(.:format) ckeditor/attachment_files#create
attachment_file DELETE /attachment_files/:id(.:format) ckeditor/attachment_files#destroy