0

In Rails 4.0.3, I try to send a http get request from rails console:

app.get '/'

it returns with response code 302 redirected.

Started GET "/" for 127.0.0.1 at 2014-09-03 11:57:11 +0200
=> 302

However, this page is a public page, shouldn't be redirected.

Any clue how can I make it working?

Community
  • 1
  • 1
fuyi
  • 2,573
  • 4
  • 23
  • 46

2 Answers2

0

I have the same issue, but that's because my app need to login as the first, so I do the following command:

>> ApplicationController.allow_forgery_protection = false
>> app.post '/users/sign_in', :user => {:email => "user@example.com", :password => "12345"}

these commands will return 302, you can now go to the root path as the following:

>> app.get '/'

this'll return Completed 200 OK, this similar question may help you.

Community
  • 1
  • 1
Mohamed Yakout
  • 2,868
  • 1
  • 25
  • 45
  • Hi Mohamed, I tried your solution, it does not work. As I said, the home page is a public page, it does not require login. – fuyi Sep 03 '14 at 17:34
0

I finnally found the problem. It is caused by a Rails middleware gem I used to check UserAgent called browser.

I have the following code to only allow "modern browsers" to access my site

Rails.configuration.middleware.use Browser::Middleware do
next if (browser.bot? or browser.search_engine?) 
redirect_to upgrade_path unless browser.modern?
end

As rails console has no UserAgent setting, it always redirects to /upgrade.

I update the code to:

Rails.configuration.middleware.use Browser::Middleware do
next if (browser.bot? or browser.search_engine? or (Rails.env == 'test') or (Rails.env == 'development') )
redirect_to upgrade_path unless browser.modern?
end

Now it works!

fuyi
  • 2,573
  • 4
  • 23
  • 46