我一直在寻找如何添加一个id选择器到link_to帮助使用haml,是可能吗?
a .haml - %a#booked{:href => "index.haml"} Link 1 b .html.erb - booking.html.erb - <%= link_to "Link 1",booking_path,:id => "booked" %> c .haml.erb - booking.haml.erb - ...??
哪一个相当于哈姆?
解决方法
link_to的工作原理与哈尔同样的方式在erb中.所以这会做你想要的:
= link_to "Link 1",:id => "booked" #=> <a id="booked" href="/bookings">Link 1</a>
您也可以这样分配一个类属性:
= link_to "Link 1",:id => "booked",:class => "some_class" #=> <a id="booked" class="some_class" href="/bookings">Link 1</a>
更多关于如何在haml:Inserting ruby中插入ruby代码
而且,所以对于将id和类传递给link_to毫无疑问,这里是一个例子from the docs:
link_to "Articles",articles_path,:id => "news",:class => "article" #=> <a href="/articles" class="article" id="news">Articles</a>