在控制器中创建一个 link_to [英] create a link_to in controller

查看:29
本文介绍了在控制器中创建一个 link_to的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将通知传递给控制器​​的视图,并且我希望是否可以创建一些指向通知的链接.

I need to pass a notice to a view from controller, and I want if can to create some link also to the notice.

我的控制器:

format.html { redirect_to purchase_order_headers_path, notice: 'PO already has RR with RR ID: ' + rr.rr_id + ', void RR first.' }

有什么办法可以让 [rr.rr_id] 变成一个链接,这样当用户点击它时就会转到它的页面吗?由于 link_to 将返回错误 "undefined method" 如果放在控制器上.

Is there any way so I can do it so the [rr.rr_id] will become a link so when the user click on it will go to it's page? Since link_to will return error "undefined method" if put on controller.

谢谢.

推荐答案

如果您使用的是 rails 3,则可以在控制器中使用 view_context.link_to(...).

if you are using rails 3, you can use view_context.link_to(...) in your controller.

更新:使用 format.html 代码

UPDATE: with the format.html code

format.html do
  redirect_to purchase_order_headers_path, notice: "PO already has RR with RR ID: #{view_context.link_to(rr.rr_id, receiving_record_header_path(rr.id))} void RR first.".html_safe
end

这篇关于在控制器中创建一个 link_to的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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