content_tag(divタグ)になったりlink_toになったりするヘルパー
詳しい要件は忘れてしまいましたが、htmlタグの要素だけ違くて、他はほぼ同じみたいなことをすることがあります。
その場合もerbで分岐処理を書かずに、blockを使ってhelperに書くとスッキリする気がしました。
module SomeHelper def content_tag_or_link_to(path, class:, is_content_tag: false, &block) if is_content_tag content_tag :div, class:, &block else link_to path, class:, &block end end end
<%= content_tag_or_link_to some_path, class: "btn", is_content_tag: @is_content_tag do %> <div class="label">cssによりボタンの見た目をしています</div> <% end %>