Rails:尝试将Id从控制器传递到视图(Rails : trying to pass Id from controller to view)

编程入门 行业动态 更新时间:2024-10-27 06:32:33
Rails:尝试将Id从控制器传递到视图(Rails : trying to pass Id from controller to view)

我是红宝石的小菜鸟..

我想传递我刚刚创建的对象的id来查看它将通过render方法获得渲染

这是我的代码如下

respond_to do |format| if @object.save format.html { render "finished_reg",param: @object.id ,notice: 'object was successfully created.' } #end

在视图中

<%= link_to 'Here' ,"/controller/#{:param}" %>

但没有任何事情发生..如何制作,如何在视图上打印?

i'm a little noob in ruby..

i want to pass id of object that i just created to view that it will get render via render method

this is my code below

respond_to do |format| if @object.save format.html { render "finished_reg",param: @object.id ,notice: 'object was successfully created.' } #end

in the view

<%= link_to 'Here' ,"/controller/#{:param}" %>

but nothing happen.. how to make that and how can i print this on the view?

最满意答案

从控制器到视图时, @instance_variables仍然存在。 所以你可以简单地做:

<%= link_to 'Here' ,"/controller/#{@object.id}" %>

@instance_variables persist when going from controller to views. So you can simply do:

<%= link_to 'Here' ,"/controller/#{@object.id}" %>

更多推荐

本文发布于:2023-08-06 03:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444849.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   控制器   Id   Rails   controller

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!