質問

私はlink_toに対して次のラッパー・メソッドを持っています:

def link_to_with_current(text, link, condition, *args)
  current_class = condition ? 'current' : nil
  link_to text, link, :class => current_class, *args
end

このサンプルで呼び出されたときます:

link_to_with_current 'My Link', '/mylink.html', true, :id => 'mylink'

次のリンクが生成されます:

<a href="/mylink" class="current">My Link</a>

なぜIDが表示されない?

役に立ちましたか?

解決

theIVの提案のおかげで、私は作品のバージョンを見つけます:

def link_to_with_current(text, link, condition, *args)
  options = args.first || {}
  options[:class] = condition ? 'current' : nil
  link_to text, link, options
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top