codeplant / simple-navigation

A ruby gem for creating navigations (with multiple levels) for your Rails, Sinatra or Padrino applications. Render your navigation as html list, link list or breadcrumbs.
http://simple-navigation-demo.codeplant.ch/
MIT License
885 stars 136 forks source link

Cannot use dash ('-') based attributes in dom_attributes #163

Closed otherjohn closed 10 years ago

otherjohn commented 10 years ago

I may just be writting this out incorrectly, but I want to do something like: <ul class="page-sidebar-menu" data-auto-scroll="true" data-slide-speed="200"> But, nothing seems to render correctly. I have tried : primary.dom_attributes = {:class => "page-sidebar-menu", [:'data-auto-scroll'] => "true", [:'data-slide-speed']=>"200"} and primary.dom_attributes = {:class => "page-sidebar-menu", "data-auto-scroll'" => "true", "data-slide-speed" =>"200"}

simonc commented 10 years ago

Hi @otherjohn,

Could you try the following and tell me if it works:

primary.dom_attributes = {
  class: 'page-sidebar-menu',
  data: {
    'auto-scroll' => true,
    'slide-speed' => 200
  }
}

I just tried it and it works like a charm. The following alternative works perfectly too.

primary.dom_attributes = { :class => 'page-sidebar-menu', 'data-auto-scroll' => 'true', 'data-slide-speed' => '200' }

Which versions of Ruby/Rails/SimpleNavigation do you use?

otherjohn commented 10 years ago

Actually, both work. I am not sure what I did wrong..

simonc commented 10 years ago

Maybe a tiny typo. Anyway, glad it works fine ;)

e-fisher commented 10 years ago

Stumbled on the same issue, turns out primary.dom_attributes must go after all items, other way it doesn't work.