ruby-on-rails - 在 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
但这不起作用 - 我怎么能访问这个变量?
解决方案
推荐阅读
- ios - 为什么我的表格视图只显示数组中的大约 20 个项目?
- javascript - 将对象道具级别与可选道具进行比较
- c - 舍入到 IEEE 754 精度但保持二进制格式
- python - ValueError:未知激活函数:my_custom_activation_function
- ios - 如何基于多个 UISwitch 状态建立更易维护的做事方式?
- javascript - 如何将多个输出控制台附加到正在运行的节点 js 应用程序
- macos - Homebrew:通过类似于 pip 的 requirements.txt 的配置文件安装?
- mysql - MySQL 8 速度慢,复合索引下降
- c++ - 如何使程序接受整数列表?
- fiware - 如何在运行 sth-comet 时修复错误?