Search code examples
ruby-on-railsruby-on-rails-4twittertwitter-gem

This webpage has a redirect loop - Rails


I'm trying to get my app to redirect to a custom route when it encounters the error:

Twitter::Error::TooManyRequests

However, I'm having difficulty for some reason and i keep getting this error:

This webpage has a redirect loop

Here's my controller:

#app/controllers/tweets_controller.rb

rescue_from Twitter::Error::TooManyRequests, with: :too_many_requests

    def too_many_requests

        redirect_to too_many_requests_path

    end

Here's my routes:

#config/routes.rb

get "/too_many_requests", to: "tweets#too_many_requests", as: :too_many_requests

I have a view within app/views/tweets named too_many_requests.html.erb

I know i must be doing something incorrectly but can someone help?

Thanks


Solution

  • Unless I'm missing something, it looks like you redirect the action to itself:

    def too_many_requests
      # Error handling.....
    
      # You should redirect this elsewhere
      redirect_to some_other_path
    end