开发者

Rails 3 POST Redirect GET - empty GET response

Using Rails 3.0.9, I'm trying to redirect after a post to the create method in UserController, Firebug shows the POST is sent correctly, my create method is executed, POST returns '302' moved temporarily. As expected the, GET request routes to the new action of the UserProfileController, HOWEVER, there is not response to the GET request!

I tried this with other controllers/actions also with the same result. Why is the GET request after redirect empty? What am I doing wrong? A standard request to /users/profile/new does return the expected GET response.

UserController

def create
  @user = User.new(params[:user]) if params[:user]
  logger.debug (params[:user])
  logger.debug @user
  logger.debug @user.valid?
  logger.debug @user.errors

  if(@user.valid?)
    session[:new_user] = @user

  开发者_如何学Go  logger.debug "Creating User Profile"
  end

  redirect_to new_user_profile_url  # controller => user_profile, action => new
end

UserProfileController

def new
  @user_profile = UserProfile.new

  # check to see if the new user is in session, if not, then redirect to previous page
  user = session[:new_user]

  logger.debug 'going to right url???'
  logger.debug request.method
  logger.debug request.format
  logger.debug request.headers
  logger.debug request.url

  respond_to do |format|
    format.html
    format.xml { render :xml => @user_profile }
  end
end

Server Log

Creating User Profile
Redirected to http://localhost:3000/users/profile/new
Completed 302 Found in 325ms


Started GET "/users/profile/new" for 127.0.0.1 at Fri Aug 05 10:38:38 -0500 2011
  Processing by UserProfileController#new as HTML
going to right url???
GET
text/html
http://localhost:3000/users/profile/new
Rendered shared/_trust_reports.haml (45.0ms)
Rendered user_profile/new.haml within layouts/application (590.0ms)
Completed 200 OK in 973ms (Views: 616.0ms | ActiveRecord: 0.0ms)


Turns out it was my own mistake, I did not realize the javascript/theme we were using defaulted to submit all forms via ajax. After changing the default behavior, it worked as expected, thanks for the suggestion Fabio.


According to that log file the server has ended its job and has rendered the output. It could be a problem with your browser (sometimes firebug and other developer tools lock the browser) or it could be a problem with the webserver. I'm assuming you're using webrick (the default one).

Please try your code with another browser and if the problem remains try with a different rails server, there are a lot of them: passenger, unicorn, mongrel, thin.

Usually I develop with passenger standalone, you could install it with gem install passenger and then from your rails root simply run

passenger start

The first time it will take some minutes because it will download nginx standalone and it will compile it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜