SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post 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:
    1. render :action=>'new'
    2. 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.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    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

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    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

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    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])
    Anyway, let's see wether it works now. Getting a little tired with this mistake hunting.

    *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.

    Thanks
    Last edited by axelsword; Dec 10, 2009 at 14:42. Reason: To add few things


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •