Ruby on rails Rails 4在"行动"之前有时不';工作不好

Ruby on rails Rails 4在"行动"之前有时不';工作不好,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我的环境 ruby 2.1.4(出现在2.1.2中) Rails 4.1.6(出现在4.1.1中)开发环境 我在操作之前设置@current\u存储 class Store::ApplicationController < ApplicationController before_action :set_current_store private def set_current_store Rails.logger.debug "set_current_store

我的环境

  • ruby 2.1.4(出现在2.1.2中)
  • Rails 4.1.6(出现在4.1.1中)开发环境
我在操作之前设置@current\u存储

class Store::ApplicationController < ApplicationController
  before_action :set_current_store

  private
  def set_current_store
    Rails.logger.debug "set_current_store is called"
    @current_store = Store.find session[:id]
  end
end

class Store::FooController < Store::ApplicationController
  def index
    @foos = Foo.where(store_id: @current_store.id)
  end
end
类存储::ApplicationController
如果要从另一个方法调用该方法,请不要将其设为私有class@HisatakeIshibashi,我不是rails超级明星,我只是想给你一个正确的编码方式。如果答案能解决问题,就接受它。。
Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = false
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.assets.debug = true
  config.assets.raise_runtime_errors = true
  config.cache_store = :redis_store, "redis://localhost:6379/0/cache", { expires_in: 90.minutes }
end
class Store::ApplicationController < ApplicationController
  helper_method :set_current_store

  private
  def set_current_store
    Rails.logger.debug "set_current_store is called"
    @current_store = Store.find session[:id]
  end
end

class Store::FooController < Store::ApplicationController
  before_action :set_current_store
  def index
    @foos = Foo.where(store_id: @current_store.id)
  end
end