Ruby on Rails:使用控制器,动作&参数 [英] Ruby on Rails : get route using controller, action & param

查看:208
本文介绍了Ruby on Rails:使用控制器,动作&参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的RoR,我正在寻找一种方法来获得一个给定的控制器,行动& param。

I am quite new to RoR and I am looking for a way of getting a route for a given controller, action & param.

类似于url_for()但没有域和协议。

Something similar to url_for() but without the domain and protocol.

params = {"controller"=>"controller", "action"=>"edit", "project_id"=>"1"}

我需要:

route = "/controller/edit/1"


$ b b

这是最好的,如果我不必手动建立路由,如果我不需要拆分url_for()的结果。

It would be best if I do not have to manually build the route and if I don't need to split the result of url_for().

RoR本身支持这样的功能?这可能是一个简单的问题,但我找不到答案。

Does RoR natively support such a feature? It's probably an easy question, but I couldn't find an answer.

推荐答案

这是帮助程序,您需要:

This is the helper that will generate a path like you want:

edit_controller_path(project_id: 1)

您可以使用此助手生成链接的完整路径(包括主持人):

You can use this Helper to generate the full path (including host) of the link:

edit_controller_url(project_id: 1)

编辑:
b $ b http://guides.rubyonrails.org/routing.html#路径和网址帮助

这篇关于Ruby on Rails:使用控制器,动作&参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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