この haml コードを変換して、リストではなくメニュー項目のドロップダウンを表示するにはどうすればよいですか?
Rails 4.0 アプリ内の既存のコード:
アプリ/ビュー/アプリケーション/_archive.html.haml
.sidebar-header=I18n.t('blog.archive')
-archive_dates.each do |date|
.archive-link=archive_link(date, '%B %Y')
アプリ/モデル/post.rb
def self.archive_dates(audience)
archive_dates = Array.new
published.send(audience).each do |post|
archive_dates << post.publish_date.to_date if archive_dates.count == 0 || post.publish_date.month != archive_dates.last.month || post.publish_date.year != archive_dates.last.year
end
archive_dates
end
アプリ/ヘルパー/application_helper.rb:
def archive_link(archive_date, format)
archive_date = archive_date.to_date
link_to I18n.l(archive_date, format: format), posts_path(month: archive_date.month, year: archive_date.year)
end
これは出力 HTML です。
http://i.stack.imgur.com/bFaxf.png
ユーザーは月を選択して、その月に作成されたすべての投稿を表示できます。同じ形式と動作を探していますが、代わりにドロップダウン メニューを使用する必要があります。