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.' } #endin 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}" %>更多推荐
发布评论