pelargir / auto-session-timeout

Provides automatic session timeout in a Rails application.
MIT License
126 stars 63 forks source link

NoMethodError (undefined method `active_url' for a Controller...) #2

Closed zipho closed 11 years ago

zipho commented 11 years ago

'active_url' seems to be breaking the Gem in my rails 3.2.11.

What could be the issue?

/home.rvm/gems/ruby-1.9.3-p392/gems/auto-session-timeout-0.9.2/lib/auto_session_timeout.rb:14:in `block in auto_session_timeout'

pelargir commented 11 years ago

Did you add the proper routes?

match 'active'  => 'sessions#active',  via: :get
match 'timeout' => 'sessions#timeout', via: :get
zipho commented 11 years ago

Thanks...i solved this particular issue.

I am now getting a JS error..

TypeError: $.PeriodicalUpdater is not a function

this line after the else seems to be throwing the error.

$.PeriodicalUpdater('/active', {minTimeout:60000, multiplier:0, method:'get', verbose:2}, function(remoteData, success) {

Do you know what might be the issue, is the a library that your GEM depends on?

I hope its not too much to ask.

pelargir commented 11 years ago

Do you have jQuery installed?

https://github.com/rails/jquery-rails

zipho commented 11 years ago

I do have jquery-rails installed and have implemented some of its function smoothly already.

pelargir commented 11 years ago

You also need to install the periodical updater plugin:

https://github.com/RobertFischer/JQuery-PeriodicalUpdater

This hasn't been documented in the README yet. Sorry about that.

(The original version of the gem used Prototype exclusively, and Prototype has a periodical updater built-in.)

zipho commented 11 years ago

Thanks Matthew

I was missing the JQuery-PeriodicalUpdater. All is working accordingly now.

wingalong commented 9 years ago

Hi, I also get 'active_url' problem, /home.rvm/gems/ruby-1.9.3-p392/gems/auto-session-timeout-0.9.2/lib/auto_session_timeout.rb:14:in `block in auto_session_timeout'.

How did you solve it?

I am unable to put match 'active' => 'sessions#active', via: :get match 'timeout' => 'sessions#timeout', via: :get in routes.rb, with error no "match" method.

My routes.rb now looks like this: ActionController::Routing::Routes.draw do |map| map.resources :session end

pelargir commented 9 years ago

Are you using Rails 4? I haven't updated this gem in a long time. The latest version of Rails may not like the routing syntax. Something like this should work:

Rails.application.routes.draw do
  get 'active' => 'sessions#active'
  get 'timeout' => 'sessions#timeout'
end
wingalong commented 9 years ago

Yes, I am now using Rails 4.2.3 Ruby 1.9.3.

All my other routes.rb code is like : ActionController::Routing::Routes.draw do |map| map.resources :session end

So I put ActionController::Routing::Routes.draw do get 'active' => 'sessions#active' get 'timeout' => 'sessions#timeout' end

at the end of routes.rb file, after tag. server has this error /home/weiming/maspore/config/routes.rb:130:in block in <top (required)>': undefined methodget' for main:Object (NoMethodError).

Thank you!

pelargir commented 9 years ago

Don't use 2 blocks. Your routing file should only have a single block. And if you're truly on Rails 4.2 you shouldn't be passing map to the block anyway:

Rails.application.routes.draw do
  resources :session
  get 'active' => 'sessions#active'
  get 'timeout' => 'sessions#timeout'
end

Are you sure you're on Rails 4.2?

wingalong commented 9 years ago

Yes, I am sure it is the Rails 4.2.3. I am maintaining the system so I am not sure how it is working like that. And the even though I replace the whole routes.rb file with ActionController::Routing::Routes.draw do ... end It does not work.

Is it possible to be something like map.resources :session map.connect '/session/active', :controller => 'session', :action => 'active' map.connect '/session/timeout', :controller => 'session', :action => 'timeout'

pelargir commented 9 years ago

I'm not sure how it's working either. A fresh Rails 4.2.3 app has a routes block that looks like this:

Rails.application.routes.draw do
 ...
end

So I'm not sure how you ended up with the old style syntax. Did you upgrade this app from a previous version of Rails? I'd suggest trying the example I posted previously:

Rails.application.routes.draw do
  resources :session
  get 'active' => 'sessions#active'
  get 'timeout' => 'sessions#timeout'
end

If that still isn't working then you have something else going on in your app that's causing your routes not to work correctly. It doesn't appear to be an issue with my plugin.

wingalong commented 9 years ago

Hi, I am not saying there is any problem with your plugin. Just asking for help on how to solve the problem. "get" is not a authorize method in my routes.rb under |map|. Is there any way to write the route config in |map| way to use the plugin?

Thank you!

levelone commented 8 years ago

Hi @pelargir, currently trying this gem out, and had this same issue with @zipho but got it resolved by adding:

match 'active'  => 'sessions#active',  via: :get
match 'timeout' => 'sessions#timeout', via: :get

My concern now is, after setting auto_session_timeout(5.minutes) in my application controller, nothing happens. I followed the steps and am unfamiliar as to what to do next. Is the timer starting? if so why don't I get timed-out after 5 minutes?

pelargir commented 8 years ago

Glad you got it working. The routes you used are, incidentally, identical to the routes I suggest in the README. :smiley:

If you tail your Rails log file you should see a GET request to the #active controller action being sent every 60 seconds. If you aren't seeing this "heartbeat" then something is wrong. You're probably getting a JavaScript error. Open the developer console in Chrome or Safari to see the error.