eva*_*anx 14 haml ruby-on-rails-3
我一直在寻找如何使用辅助id器添加选择器,这可能吗?link_tohaml
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 - ...??
Run Code Online (Sandbox Code Playgroud)
这相当于ha中的b?
Chr*_*erg 28
link_to在haml中的工作方式与在erb中完全相同.所以这将做你想要的:
= link_to "Link 1", booking_path, :id => "booked"
#=> <a id="booked" href="/bookings">Link 1</a>
Run Code Online (Sandbox Code Playgroud)
您还可以通过以下方式分配类属性:
= link_to "Link 1", booking_path, :id => "booked", :class => "some_class"
#=> <a id="booked" class="some_class" href="/bookings">Link 1</a>
Run Code Online (Sandbox Code Playgroud)
有关如何在haml中插入ruby代码的更多信息:插入ruby
并且,对于传递id和类没有任何疑问link_to,这是一个来自文档的示例:
link_to "Articles", articles_path, :id => "news", :class => "article"
#=> <a href="/articles" class="article" id="news">Articles</a>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27105 次 |
| 最近记录: |