从 html 转换为 rail [英] Converting from html to rail

查看:38
本文介绍了从 html 转换为 rail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有这个链接:

<a href="#rating-box" class="login-window">Rate & Commment</a>

我想将其转换为 rails 样式,可能类似于:

and I would like to convert this into rails style, maybe something like:

<%= link_to 'Rate & Comment', :anchor => "rating-box", :class => "login-window"%>

可以吗?

编辑 1

还有一个问题.

当我使用

<%= link_to "Rate & Commment", comment_path(:post_id => post.id), :class => "post" %>

我可以将一些数据(在本例中为 post id)传递给控制器​​,并且我可以通过引用参数来使用这些数据.

I can pass on some data (in this case, the post id) to the controller and i can use the data by referencing to params.

所以如果路径变成一个div元素,比如

So if the path becomes a div element, like

<%= link_to 'Rate & Comment', "#rating-box", :class => "post" %>

我仍然可以通过括号来传递数据吗?

can I still pass on data by bracketing it?

编辑 2

在我看来,我曾尝试这样做:

I have tried to do this in my view:

<a href="#rating-box" class="post" data-post_id = '<%= p.id %>'>Rate & Comment</a>

但是我无法使用以下代码检索控制器中的数据:

However I couldn't retrieve the data in controller with the code below:

def create
@comment.post_id = params[:post_id]
end

推荐答案

最后不得不用这个来解决我自己的问题:

At the end I have to use this to solve my own problem:

<%= link_to "Rate & Commment", fetch_rating_path(:post_id => p.id), :class => "login-window" %>

这篇关于从 html 转换为 rail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆