简体   繁体   中英

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. 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. 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]

you may need to update your render line to

render :template => "ctrl/update"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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