2
問題是如此簡單,我沒有任何線索可能是錯誤的。rspec說沒有路由匹配,但路由在瀏覽器中工作
我有這個天賦:
it "/fr/admin/articles/new" do
expect(:get => "/fr/admin/articles/new").to route_to(:controller => 'articles', :action => 'new')
end
當我瀏覽本地主機:3000/FR /管理/用品/新工作!
,但我的測試說:
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)>'
我的routes.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
耙路輸出:
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
請運行'耙routes'和輸出增加的問題。 –
我有同樣的問題 – fespinozacast