Ruby On Rails/작은 팁2011/06/13 15:00


작업을 하다보면 종종 불필요한 prefix가 붙는 경우가 생긴다.

resources :article do
  resources :article_log
end

resources :log


사실 큰 문제는 없지만, article_log path을 적어줘야 할때

article_article_log_path

이런 요상한(?) naming을 가진 path가 되어버린다.

나 같이 깔끔한 사람(응?)은 이런거 눈뜨고 못본다.
난 무슨 일이 있어도

article_log_path

이렇게 쓰고 싶어 근질할테니 말이다.
당신도 그런가? 
동지! 함께 원피스를 찾자!(응?)

이런 경우

:as 

를 써주면 우리가 원하는(설마 나만 원하는건 아니겠지?) 형태로 사용할 수 있게 된다.

resources :article do
  resources :article_log, :as => :log
end

resources :log


이렇게 :as를 추가해주게 되면

article_article_log_path

가 아닌

article_log_path

로 path가 잡히게 된다.
못믿겠으면 

rake routes

해보라!


크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by Johan Kim hiphapis

TRACKBACK http://hiphapis.net/trackback/194 관련글 쓰기

댓글을 달아 주세요