SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Simply Rails 2 Ch.8 Controller
-
Dec 9, 2009, 17:29 #1
- Join Date
- Dec 2009
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Simply Rails 2 Ch.8 Controller
Hello!
I followed this nice book, but in Chapter 8 I ran into trouble when creating login form.
I think I did everything right, didn't use code base but typed code manually. I can enter anything into login form but the redirect doesn't function:
- render :action=>'new'
- redirect_to stories_path
Maybe it has something to do with the update fail that is described in Chapter 1. I ran into errors when using console commands to update rails and ruby.
Chapter 8 describes that the code in sessions_controller.rb should skip create.html.erb view when action 'new' is used, that is the form written earlier is submitted, but that doesn't occur in my case.
Please help.
-
Dec 9, 2009, 23:46 #2
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
Hi axelsword, welcome to the forums.
Does your sessions_controller.rb file look something like (depending on where you are in chapter 8)
Code Ruby:class SessionsController < ApplicationController def new end def create @current_user = User.find_by_login_and_password( params[:login], params[:password]) if @current_user session[:user_id] = @current_user.id if session[:return_to] redirect_to session[:return_to] session[:return_to] = nil else redirect_to stories_path end else render :action => 'new' end end def destroy session[:user_id] = @current_user = nil end end
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Dec 10, 2009, 12:24 #3
- Join Date
- Dec 2009
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
All right, I see the mistake. Well, I did feel sleepy and tired, my mind on different other things rather than programming in Ruby that I needed to do. I'll have to be more careful next time.
Heres my sessions_controller.rb
Code Ruby:class SessionsController < ApplicationController def new @current_user=User.find_by_login_and_password(params[:login], params[:passrowd]) if @current_user session[:user_id]=@current_user.id redirect_to stories_path else render :action=>'new' end end def create end def destroy end end
-
Dec 10, 2009, 15:38 #4
- Join Date
- Dec 2009
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What else? Why is there no "edit post" button? Noticed one earlier, must be time sensitive. Hmmph. All right, spotted the error: what is passrowd?
Code Ruby:@current_user=User.find_by_login_and_password( params[:login], params[:passrowd])
*Edit*
Still, there is this second issue - back in who-knows-what-chapter when the button "shove it" was created, in my case it does not work as expected. I press the button but no redirect. I refresh the page manually and I see that the score has increased. I could use some help debugging that too. I use WinXp and FireFox 3.5.5.
ThanksLast edited by axelsword; Dec 10, 2009 at 15:42. Reason: To add few things
Bookmarks