简体   繁体   English

在Rails中,如何从视图中输出动作的名称?

[英]In Rails, how can you output the name of the action from inside the view?

If I render the update action from inside the create action, is there a way for the "update" view (ie update.html.erb) to know which action rendered it. 如果我从创建操作内部渲染更新操作,是否有办法让“更新”视图(即update.html.erb)知道哪个操作呈现了它。 I want the update view to print out the action name "create" when the create action renders it and print out the word "update" when the update action renders it. 我希望更新视图在创建操作呈现时打印出操作名称“create”,并在更新操作呈现时打印出“update”一词。 The problem is render seems to defer control to the invoked action so for all intents and purposes the update view always thinks it's coming from the update action. 问题是呈现似乎将控制推迟到被调用的操作,因此对于所有意图和目的,更新视图始终认为它来自更新操作。

class CtrlController < ApplicationController

  def create
    render(:action=>"update")
  end

  def read
  end

  def update
  end

  def delete
  end

params[:action] PARAMS [:动作]

you may need to update your render line to 您可能需要将渲染线更新为

render :template => "ctrl/update"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM