0
기본적으로 모두 동일한 기능을하는 헬퍼가 많이 있습니다.도우미 메서드 선언을 어떻게 말릴 수 있습니까?
def subtitle(page_subtitle)
content_for(:subtitle) { page_subtitle }
end
def header(page_header)
content_for(:header) { page_header }
end
def auto_header(page_auto_header)
content_for(:auto_header) { page_auto_header }
end
def header_image(page_header_image)
content_for(:header_image) { page_header_image }
end
def bodyclass(page_bodyclass)
content_for(:bodyclass) { page_bodyclass }
end
그리고 더 많은이 있습니다 ...
이 코드 건조 할 수있는 방법 내 질문은?
는 뭔가이 시도하지만 난이 나에게 코드 냄새처럼 보이는content_for_helpers = ["title","subtitle","logocolor"]
content_for_helpers.each do |helper|
def helper(helper)
content_for(helper.parameterize.underscore.to_sym) { helper }
end
end
작동하지 않았다. 보기가 어떻게 생겼습니까? 더 나은 방법이있을 것입니다. –
나는 또한 확신한다. 이 일을하는 더 좋은 방법을 보여 주시겠습니까? – Martin
이러한 모든 도우미로 어떤 문제를 해결하려고합니까? 보기를 보여줄 수 있습니까? –