Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Redirect_to @user does not work, stays on my "new" user page.


  • Please log in to reply
6 replies to this topic

#1 jschrock1

jschrock1

    Dispatcher

  • Members
  • 48 posts
  • LocationIndianapolis

Posted 23 November 2013 - 07:59 PM

Well I've spent three hours on this now and going completely mad.  I have a very simple app, not too disimilar from the tutorial.

I have a number of simple models, all of which I can enter in "new" data from the new page, click save, and in my controller it redirects me to the "show" page.  simple as anything can be.

 

I had this working for my user page, but now when I click save on the "new" page after entering my user info, it does NOT redirect me to the "show" page and rather simply keeps me at my "new" page, nothing was redrawn...  and im totally baffeled as the log file clearly indicates the "show" page is rendering!   As the log file shows below, I even added a puts "+++++ in show users" in the show.html.erb....   I also  can enter localhost:3000/users/51 as a url and it nicely pops me into my "show" page so I know that page has no errors..  Below is the controller, and log files. 

 

If anybody has any idea what might be wrong, I'd appreciate it, thanks..

 def create
    logger.debug("Jay start UsersController.create")
    @user = User.new(user_params)
    if @user.save_with_exception_handler
            puts "+++++++++++++++++++++++++++ 1"  
	    flash.now[:notice] = "Welcome to WerkHub!"
	    sign_in @user
            puts "+++++++++++++++++++++++++++ 1a"  
            redirect_to @user
    else
      flash.now[:error] = "Error!"
       puts "+++++++++++++++++++++++++++ errors should show: " 
      render 'new'
    end
end
  def show
    logger.debug("Jay start UsersController.show")
    @user = User.find(params[:id])	
  end
+++++++++++++++++++++++++++ 1a
Redirected to http://localhost:3000/users/59
Completed 302 Found in 392ms (ActiveRecord: 125.0ms)


Started GET "/users/59" for 127.0.0.1 at 2013-11-23 14:43:42 -0500
Processing by UsersController#show as JS
  Parameters: {"id"=>"59"}
Jay start UsersController.show
  User Load (294.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 59 LIMIT
+++++ in show users
  Rendered users/show.html.erb within layouts/application (142.0ms)
Jay in full_title Start
  Rendered layouts/_shim.html.erb (0.0ms)

Jay start SessionsHelper.signed_in?
Jay start SessionsHelper.current_user token is: gbH0rHJqqUeieOnVy7HQBg
  User Load (0.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`remember_token`
Jay: User is signed in? ==> true


#2 james

james

    Guard

  • Members
  • 223 posts
  • LocationLeeds, U.K.

Posted 24 November 2013 - 04:32 AM

You are rendering a patial called _shim.html.erb

Rendered layouts/_shim.html.erb 

Whatever is in this partial is what will be shown

 

You get a 302 response which is a redirect. It looks like some kind of authentication Completed

 302 Found in 392ms (ActiveRecord: 125.0ms)

Then you get the

Rendered layouts/_shim.html.erb (0.0ms)

I have no idea what shim is but maybe you should be looking at your authentication process. I also have no idea what Jay is or where it is coming from.. This may also be related.

 

Anyway, hope that gives you a starting point for tracking down your issue.

 

 


Programming is just about problem solving!

#3 Ohm

Ohm

    Driver

  • Moderators
  • 490 posts
  • LocationCopenhagen

Posted 24 November 2013 - 11:25 AM

It seems that you are posting to the create form and getting the JS response

Processing by UsersController#show as JS

If you really want the JS response, but still want a redirect, you'll have to create the redirect in your Javascript being rendered.


  • james likes this

Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk


#4 james

james

    Guard

  • Members
  • 223 posts
  • LocationLeeds, U.K.

Posted 24 November 2013 - 01:50 PM

Nice spot Ohm, I missed that, Guess that's what happens when answering questions at 4 in the morning. although that doesn't explain the log output

 

Rendered users/show.html.erb within layouts/application (142.0ms)

 


Programming is just about problem solving!

#5 jschrock1

jschrock1

    Dispatcher

  • Members
  • 48 posts
  • LocationIndianapolis

Posted 24 November 2013 - 08:07 PM

You are rendering a patial called _shim.html.erb

Rendered layouts/_shim.html.erb 

Whatever is in this partial is what will be shown

 

You get a 302 response which is a redirect. It looks like some kind of authentication Completed

 302 Found in 392ms (ActiveRecord: 125.0ms)

Then you get the

Rendered layouts/_shim.html.erb (0.0ms)

I have no idea what shim is but maybe you should be looking at your authentication process. I also have no idea what Jay is or where it is coming from.. This may also be related.

 

Anyway, hope that gives you a starting point for tracking down your issue.

Yea, I didn't think this would be an easy find for anyone..  The _shim is a partial that I used after doing the tutorial, apparently something needed if the IE is < version 9..  The _shim,  header and footer is in the layout rendering processes… Below James had some comments about noticing the JS running during a "Show" render...    Im not sure, but it does lead me to one of the last things I implemented, a fancier combo box I found in one of the rails casts..  It could be related..



#6 jschrock1

jschrock1

    Dispatcher

  • Members
  • 48 posts
  • LocationIndianapolis

Posted 24 November 2013 - 08:08 PM

Yea, I didn't think this would be an easy find for anyone..  The _shim is a partial that I used after doing the tutorial, apparently something needed if the IE is < version 9..  The _shim,  header and footer is in the layout rendering processes… Below James had some comments about noticing the JS running during a "Show" render...    Im not sure, but it does lead me to one of the last things I implemented, a fancier combo box I found in one of the rails casts..  It could be related..

oh, and the "Jay" lines are my debuggin "puts" statements...



#7 jschrock1

jschrock1

    Dispatcher

  • Members
  • 48 posts
  • LocationIndianapolis

Posted 24 November 2013 - 08:14 PM

It seems that you are posting to the create form and getting the JS response

Processing by UsersController#show as JS

If you really want the JS response, but still want a redirect, you'll have to create the redirect in your Javascript being rendered.

I did implement a fancy combo box via railscasts, the combo box does exist on the "show" page, so perhaps you found the culprit.  Since then however I decided to start from scratch with the user environement and add my code in one peace at a time...  I've completed most of it including the combo box and did not hit the problem since.  Everything works find including the combo box...  so, its disapointing not knowning what happened, but at least my pages render fine now, and analyzing the log files, they show the same information as when the pages were not rendering correctly.  weird.. 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users