在 Link_to 中传递参数 [英] Pass Parameters in Link_to

查看:86
本文介绍了在 Link_to 中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 Rails 中的 link_to 方法传递参数.我知道有一种方法可以通过 URL 做到这一点,但我真的不想那样做.有没有办法通过链接传递参数而不将其添加到链接本身?

I would like to pass a parameter through a link_to method in Rails. I know there is a way to do it via the URL but I really don't want to do that. Is there any way to pass a param via a link without adding it to the link itself?

我知道在 PHP 中您可以发布然后使用 post 变量检索该值.Rails 中有类似的东西吗?

I know in PHP you can post and then retrieve that value by using the post variable. Is there something similar in Rails?

推荐答案

link_to 签名如下:

link_to(body, url_options = {}, html_options = {})

所以,POST 看起来像(假设您想 POST 用户的数据):

So, POST would look like (lets say you want to POST user's data):

link_to "Link text", some_path(:foo => "bar", :baz => "quux"), user: @user, :method => :post

可以使用params[:user]

这篇关于在 Link_to 中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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