首页 > 解决方案 > 在 after_action 中从 Rails 视图访问 instance_variable

问题描述

我想在 after_action 中访问 instance_variable(或变量的任何排列)。例如(苗条):

- @main_show_cache_hit = 'bees'
- cache [@lawyer] do
  - @main_show_cache_hit = 'double-bees'

并在我的控制器中有:

  after_action :memcached_stats, only: :show
  
  ...

  def show
    # can put @main_show_cache_hit = "birds" 
  end

  ...      
  def memcached_stats
    Rails.logger.info "------ START memcached_stats -------"
    Rails.logger.info "---#{@main_show_cache_hit}-----"
    Rails.logger.info "------ END memcached_stats -------"
  end

但这不起作用 - 我怎么能访问这个变量?

标签: ruby-on-rails

解决方案


推荐阅读