css - 从 html 转换为 rail

标签 css html ruby-on-rails-4

我这里有这个链接:

<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/

相关文章:

android - 仅允许 Android 应用程序访问 Rails API 的最佳实践

html - CSS:如何更改 bootstrap LESS code.less 源代码以自定义我的代码着色?

css - Font Awesome 5 - 为什么调整字体系列时图标消失?

html - 如何使 div 具有类似表格的边框?

HTML contenteditable 与不可编辑的岛屿

HTML/CSS 下拉菜单位置

ruby-on-rails - 为什么当 rails redirect_to 成功调用新的 url 时浏览器的地址没有改变?

CSS 闪烁的星星

javascript - 自动图像缩放?

ruby - 为 Ruby on rails 中的 1 亿条记录生成 CSV/Excel 文件?