开发者

Routing Discrepancy Between Development and Production Environments (Ruby on Rails)

开发者 https://www.devze.com 2023-03-05 18:10 出处:网络
I\'m writing an app in Rails (v3.0.5), which I\'m deploying to Heroku. When I visit http://localhost:3000/places/new in my development environment, I\'m taken to the appropriate page (the form for cr

I'm writing an app in Rails (v3.0.5), which I'm deploying to Heroku.

When I visit http://localhost:3000/places/new in my development environment, I'm taken to the appropriate page (the form for creating a new place). Everything works as expected (I can create new places).

When I try to visit the corresponding page (http://example.heroku.com/places/new) in my Heroku production environment, I'm routed back to the home page for my app.

The contents of my routes.db file:

ExampleSite::Application.routes.draw do

    resources :users
    resources :sessions, :only => [:new, :create, :destroy]
    resources :places

    root              :to => 'pages#home'
    match '/contact', :to -> 'pages#contact'
    match '/about',   :to -> 'pages#about'
    match '/signin',  :to -> 'sessions#new'
    match '/signout', :to -> 'sessions#destroy'

end

What might be a cause for the discrepancy between development and production?

Note: the only actions I've built out so far in my 'places' controller are 'new' and 'create' (both of which perform as expected in the development environment). Not sure that should be relevant, but keep it in mind. Also, all of the 'users' actions and routes seem to be working as expected in both development and production.

EDIT: As noted in the comment below, /places/new is an authentication-protected page, but in both cases I'm trying this while logged in. Also, when I do try to access /places/new in my production environment while not logged in, the appropriate redirect (to my /signin page) works as expected.

My Heroku log from an attempt at getting /place/new:

2011-05-12T23:37:30+00:00 app[web.1]: Started GET "/places/new" for 74.87.126.82 at Thu May 12 16:37:30 -0700 2011
2011-05-12T23:37:30+00:00 app[web.1]:   Processing by PlacesController#new as HTML
2011-05-12T23:37:30+00:00 app[web.1]: Redirected to http://example.heroku.com/
2011-05-12T23:37:30+00:00 app[web.1]: Completed 302 Found in 4ms
2011-05-12T23:37:30+00:00 heroku[router]: GET example.heroku.com/places/new dyno=web.1 queue=0 wait=0ms service=9ms bytes=631
2011-05-12T23:37:30+00:00 app[web.1]: 
2011-05-12T23:37:30+00:00 app[web.1]: 
2011-05-12T23:37:30+00:00 app[web.1]: Started GET "/" for 74.87.126.82 at Thu May 12 16:37:30 -0700 2011
2011-05-12T23:37:30+00:00 app[web.1]:   Processing by PagesController#home as HTML
2011-05-12T23:37:30+00:00 app[web.1]: Rendered layouts/_header.html.erb (4.3ms)
2011-05-12T23:37:30+00:00 app[web.1]: Rendered pag开发者_开发百科es/home.html.erb within layouts/application (5.7ms)
2011-05-12T23:37:30+00:00 app[web.1]: Completed 200 OK in 7ms (Views: 3.5ms | ActiveRecord: 5.8ms)
2011-05-12T23:37:30+00:00 heroku[router]: GET example.heroku.com/ dyno=web.1 queue=0 wait=0ms service=14ms bytes=2357


As it turns out, I had a second (forgotten, since I changed the scope of 'users') authentication condition which checked for admin-level status. THAT condition redirected to the home page if the current user was not an admin.

The test user I created in my development environment IS an admin (since I created that user before switching the scope), while the test user I created in the production environment IS NOT an admin (hence the redirect).

Thanks all for your help! While this mistake was an oversight, your suggestions taught me about a few new diagnostic tools I hadn't thought to use.

0

精彩评论

暂无评论...
验证码 换一张
取 消