我这里有这个链接:
<a href="#rating-box" class="login-window">Rate & Commment</a>
我想把它转换成 rails 风格,可能是这样的:
<%= link_to 'Rate & Comment', :anchor => "rating-box", :class => "login-window"%>
有可能吗?
编辑 1
还有一个问题。
当我使用
<%= link_to "Rate & Commment", comment_path(:post_id => post.id), :class => "post" %>
我可以将一些数据(在本例中为帖子 ID)传递给 Controller ,我可以通过引用参数来使用这些数据。
所以如果路径变成一个div元素,比如
<%= link_to 'Rate & Comment', "#rating-box", :class => "post" %>
我还能通过括号传递数据吗?
编辑2
在我看来,我已经尝试这样做了:
<a href="#rating-box" class="post" data-post_id = '<%= p.id %>'>Rate & Comment</a>
但是我无法使用以下代码在 Controller 中检索数据:
def create
@comment.post_id = params[:post_id]
end
最佳答案
链接在rails样式中的转换为:
<%= link_to "Rate & Commment", "#rating-box", :class => "login-window" %>
关于css - 从 html 转换为 rail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32255387/