Uno scrittoio digitale …

9 giugno 2016

can I access session variable in model

Archiviato in: rails — Tag: — admin @ 10:13

Yes you could access the session variable in model. Paste the below
code in application.rb
————–

  around_filter :you_dont_have_bloody_clue

  protected

  def you_dont_have_bloody_clue
    klasses = [ActiveRecord::Base, ActiveRecord::Base.class]
    methods = ["session", "cookies", "params", "request"]

    methods.each do |shenanigan|
      oops = instance_variable_get(:"@_#{shenanigan}")

      klasses.each do |klass|
        klass.send(:define_method, shenanigan, proc { oops })
      end
    end

    yield

    methods.each do |shenanigan|
      klasses.each do |klass|
        klass.send :remove_method, shenanigan
      end
    end

  end

————–

Now continue using the session variable in model. It works for me.
Thanks,
Sadeesh.

Nessun commento »

Non c’è ancora nessun commento.

RSS feed dei commenti a questo articolo. TrackBack URL

Lascia un commento

Funziona con WordPress