다시 쓰는 사진 포트폴리오 사이트 및 URL의 형식을 수행 할 필요가 레일에 지정된 경로에 질식.RSpec에 3
[site] .com 및 [site] .com/portfolio가 루트로 확인되어야합니다.
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
좋아, 나는 돈이다. 나는 변수를 끌어 오기 위해 globbing을 사용하고 있기 때문에 질식 해 버렸다. 그래서 portfolio_photo_path는 실제로 아무데도 가지 않는다. 나는 내가해야 할 일에 대해 혼란 스러웠다. 그리고 그것은 automagic 경로가 아니다. 다른 방법으로 경로를 동적으로 생성해야합니다. 컨트롤러에서 redirect_to를 사용하면 다시 끊어 지지만 그 범위를 벗어나는 것은 흥미 롭습니다. – user1279629