重新编写摄影作品集网站,网址必须遵循以下格式:
[site].com/portfolio/[category]/[image]
以匹配当前的实施。
[site] .com和[site] .com / portfolio应解析为root。我的路线文件如下:
root :to => 'portfolio#index'
match '/portfolio', :to => 'portfolio#index'
match '/portfolio/*category/*photo', :to => 'portfolio#photo'
match '/portfolio/*category', :to => 'portfolio#photo'
我在标题中添加了一个链接:
%li= link_to "Portfolio", root_path
这很好,但是当我添加:
%li= link_to "Editorial", portfolio_photo_path
我的网页在浏览器中解析得很好,但是rspec对我说不出话来;即使是以前运行良好的最简单的http成功测试现在也会返回:
1) PortfolioController GET 'index' returns http success
Failure/Error: get 'index'
ActionView::Template::Error:
undefined local variable or method `portfolio_photo_path' for #<#<Class:0x572d210>:0x5733d68>
# ./app/views/layouts/_header.html.haml:7:in `_app_views_layouts__header_html_haml__420220390_28357236'
# ./app/views/layouts/application.html.haml:10:in `_app_views_layouts_application_html_haml__156489427_30065868'
# ./spec/controllers/portfolio_controller_spec.rb:8:in `block (3 levels) in <top (required)>'
(当我耙路线时,我得到以下内容)
$ rake routes
root / portfolio#index
portfolio /portfolio(.:format) portfolio#index
/portfolio/*category/*photo(.:format) portfolio#photo
/portfolio/*category(.:format) portfolio#photo
答案 0 :(得分:1)
您应该添加“:as =&gt;:portfolio”声明:
match '/portfolio', :to => 'portfolio#index', :as => :portfolio
答案 1 :(得分:0)
在上面的评论中回答;我已经定义了变量全局路由,并且脑子里没有意识到我必须直接和动态地构建链接。