SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 48 of 48
  1. #26
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    This is a verbose version:

    redirect_to({:action => 'index'});

    We don't need parentheses and semicolons in Ruby:

    redirect_to {:action => 'index'}

    If you pass a hash in the last parameter you don't have to write the accolades:

    redirect_to :action => 'index'
    so at the end:

    1) "redirect_to" is a method
    2) "{:action => 'index'}" is the only argument to that method and it is a ruby Hash
    3) this method call can be rewritten without argument parenthesis 'cause there is only one argument to this method
    4) also the curly braces can be left out from the Hash literal

    is that all right?

    P.S.
    Where is the receiver of that method call?

    P.P.S.
    Anyway in the book at the beginning only explains that parenthesis are optional only in methods that are called with no arguments not also in method call with one argument. Or can i left out parenthesis also in method call with multiple arguments?

  2. #27
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    at page 62 then there is the line:

    fox.is_a? String


    ...there is not introdiced nor explained for the first time why the argument (String) to that method has no parenthesis around it being it a method with at least one parameter.

  3. #28
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Enjoying the book so far but run into a couple of problems...

    First and foremost, I have to say I am really enjoying the book. I played around with rails quite some time ago on a linux box but, got tied up with scafolding, got bored and moved on to other projects. This book has turned that attitude around 180 degrees. Now, as I read the book, I'm thinking about how I can include ROR in my next project!

    That said, I've got a couple of problems with the version of gems running as well as functional testing.

    Problem #1 gem and the gem update.

    I'm running InstantRails 1.3a on my laptop (XP Home SP2) as suggested on page 17 and I'm pretty sure everything was going well until I read the correction about page 19 paragraph 1.

    As soon as I ran: gem update --system I began getting console warnings "require_gem is obsolete. Use gem instead."

    I've also lost the ability to update rails with the command shown on page 19: gem install rails --include-dependencies. It returns an error.

    Now I've really buggered things up by running gem cleanup. It has removed most of the packages required to run ROR and I don't have ability to reinstall the packages. I don't suggest anyome run this command unless they realy know what they're doing

    Problem #2 Testing and assert_select
    On Page 177 in functional testing the test_should_show_form is causing me some grief. Before I botching things right up I had pretty well determined that for some reason my system wasn't recognizing assert_select.

    Code:
    def test_should_show_new_form
        get :new
        assert_select 'form p', :count => 3
      end
    Now that the system is all buggered up I can't run the test however I believe the error was something to do with an unrecognized method and If I pull that test out, everything worked just fine.

    I'm off to rebuild my ROR environment now but if there are any tips about the testing problem I'd appreciate it. Also any help on the environment might be helpfull as well. As I mentioned my gem install command is pretty much useless now so it looks like a fresh install will be required.

    Cheers,
    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  4. #29
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My advice is to not bother with InstantRails and grabe the Ruby one click installer - install it and then use gem to install rails. Make sure you get 1.2 for assert_select.

  5. #30
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the advice Luke.
    I'll give that a whirl (and I see it has 1.8.4).

    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  6. #31
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need parentheses at all when calling methods:

    this is ok: foo a, b, c
    but this will generate a warning: foo bar a
    you should use this instead: foo(bar a) or foo bar(a) or foo(bar(a))

    The receiver of redirect_to is self (self is the receiver for ALL method calls that don't have an explicit receiver as in "foo".length). self is the controller object in this case (Rails creates this object for you).

  7. #32
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    An update on my testing and Gem troubles

    In case anyone else runs into the trouble I've had with InstantRails and the text.

    Against luke's advice I reinstalled InstantRails. (In my defence I had already begun the unZip process and figured what the heck, might as well see where this goes)

    I did not do the gem update --system as suggested in the Errors and Typos page because I think that's what got me to the sorry state I was in this morning

    I did do the gem install rails --include-dependencies

    Once I got everything settled in I created the shovell app using rails shovell but it didn't fire up in script/server for some reason. The demo apps do but shovell would not. Fortunately, I had a copy of my existing shovel app as it is described up to about page 177 so I deleted the freshly created one and replaced it with a copy of the saved version. Low and behold it fired up!

    Ran the rake test:functionals got the error about assert_select

    I checked my web environment and it said I was running Rails 1.1.2 so I did the gem install rails -v=1.2.2 which was successfull.

    Ran the test again same thing

    Rebooted script server, checked the environment still 1.1.2!

    Then I opened and edited the shovel\config\environment.rb file. It has a line that forces back to 1.1.2:
    Code:
    # Be sure to restart your web server when you modify this file.
    
    # Uncomment below to force Rails into production mode when 
    # you don't control web/app server and can't set it the proper way
    # ENV['RAILS_ENV'] ||= 'production'
    
    # Specifies gem version of Rails to use when vendor/rails is not present
    RAILS_GEM_VERSION = '1.1.2'
    I edited it to 1.2.2 and now it seems my tests are working as they should at least with assert_select.

    EDIT: Commenting out the line also cures the problem

    Andrew
    Last edited by awasson; Feb 27, 2007 at 17:30.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  8. #33
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    You don't need parentheses at all when calling methods:

    this is ok: foo a, b, c
    but this will generate a warning: foo bar a
    you should use this instead: foo(bar a) or foo bar(a) or foo(bar(a))

    The receiver of redirect_to is self (self is the receiver for ALL method calls that don't have an explicit receiver as in "foo".length). self is the controller object in this case (Rails creates this object for you).
    thanks very clear.

  9. #34
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    awasson-

    You are 'da man'! I was also stuck on page 177 with the assert_select error, and changing environment.rb finally fixed the problem for me, too.

    I cannot express the frustration i was encountering after countless install/updates of gem and rails to no avail... let's just say that if i didn't find your post when i did, i would not be typing this reply right now- instead i'd be at the hospital getting my knuckles stitched up while planning a trip to the computer store to replace my monitors.

    Thanks!

  10. #35
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Right on, Glad that helped.

    There were some tense moments after I expertly busted my setup with gem --update system followed by gem cleanup

    Once I fixed that mess and was back in the game, I knew there had to be a file I could adjust for the environment and it was dead easy to fix once I found it.

    Now, on to page 178!

    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  11. #36
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I'm having some trouble with test:functionals around page 277.

    Results show: 22 tests, 45 assertions, 4 failures, 3 errors

    The 4 of the troubled items are the tests that should be using the protected methods for get_with_user and post_with_user. I have placed the protected methods at the bottom of my story_controller_test.rb as indicated on pg 274:
    Code:
      protected
      def get_with_user(action, parameters = nil, session = nil, flash = nil)
        get action, parameters, :user_id => users(:patrick).id
      end
      
      def post_with_user(action, parameters = nil, session = nil, flash = nil)
        post action, parameters, :user_id => users(:patrick).id
      end
    I wonder if this is in the wrong place as it doesn't seem to be working as described.

    I'll work out the other 3 problems once I have this one dealt with.

    Any ideas?
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  12. #37
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Can you post the failing tests and any other output generated when you run the test cases?

  13. #38
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Hey Vinnie,
    Thanks for the quick response. Here's the info I got back on my test. It's very long:
    Code:
      
    C:\INSTAN~1>CD C:\InstantRails
    
    C:\InstantRails>PATH C:\InstantRails\ruby\bin;C:\InstantRails\mysql\bin;C:\WINDO
    WS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\QuickTime\QTSys
    tem\;C:\Program Files\Common Files\Adobe\AGL;C:\INSTAN~1\ruby\bin;C:\INSTAN~1\Ap
    ache;C:\INSTAN~1\PHP
    
    C:\InstantRails>cd rails_apps
    
    C:\InstantRails\rails_apps>dir
     Volume in drive C is S3A1192D001
     Volume Serial Number is 4003-2C26
    
     Directory of C:\InstantRails\rails_apps
    
    27/02/2007  12:50 PM    <DIR>          .
    27/02/2007  12:50 PM    <DIR>          ..
    27/02/2007  12:42 PM    <DIR>          cookbook
    27/02/2007  12:50 PM    <DIR>          shovell
    27/02/2007  11:07 AM    <DIR>          typo-2.6.0
                   0 File(s)              0 bytes
                   5 Dir(s)  30,233,878,528 bytes free
    
    C:\InstantRails\rails_apps>cd shovell
    
    C:\InstantRails\rails_apps\shovell>rake test:functionals
    (in C:/InstantRails/rails_apps/shovell)
    C:/InstantRails/ruby/bin/ruby -Ilib;test "C:/InstantRails/ruby/lib/ruby/gems/1.8
    /gems/rake-0.7.1/lib/rake/rake_test_loader.rb" "test/functional/account_controll
    er_test.rb" "test/functional/story_controller_test.rb"
    Loaded suite C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rak
    e_test_loader
    Started
    ...F...EF...EDEPRECATION WARNING: votes_count  See http://www.rubyonrails.org/de
    precation for details. (called from votes_count at C:/InstantRails/ruby/lib/ruby
    /gems/1.8/gems/activerecord-1.15.2/lib/active_record/deprecated_associations.rb:
    7)
    ...FFDEPRECATION WARNING: votes_count  See http://www.rubyonrails.org/deprecatio
    n for details. (called from votes_count at C:/InstantRails/ruby/lib/ruby/gems/1.
    8/gems/activerecord-1.15.2/lib/active_record/deprecated_associations.rb:7)
    .DEPRECATION WARNING: votes_count  See http://www.rubyonrails.org/deprecation fo
    r details. (called from votes_count at C:/InstantRails/ruby/lib/ruby/gems/1.8/ge
    ms/activerecord-1.15.2/lib/active_record/deprecated_associations.rb:7)
    .DEPRECATION WARNING: votes_count  See http://www.rubyonrails.org/deprecation fo
    r details. (called from votes_count at C:/InstantRails/ruby/lib/ruby/gems/1.8/ge
    ms/activerecord-1.15.2/lib/active_record/deprecated_associations.rb:7)
    .E
    Finished in 1.232 seconds.
    
      1) Failure:
    test_should_redirect_after_login_with_return_url(AccountControllerTest)
        [C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_co
    ntroller/assertions/response_assertions.rb:86:in `assert_redirected_to'
         C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_co
    ntroller/assertions/response_assertions.rb:35:in `assert_redirected_to'
         ./test/functional/account_controller_test.rb:42:in `test_should_redirect_af
    ter_login_with_return_url']:
    response is not a redirection to all of the options supplied (redirection is <{"
    controller"=>"story"}>), difference: <{"action"=>"new"}>
    
      2) Error:
    test_should_add_story(StoryControllerTest):
    NoMethodError: You have a nil object when you didn't expect it!
    You might have expected an instance of ActiveRecord::Base.
    The error occurred while evaluating nil.new_record?
        ./test/functional/story_controller_test.rb:40:in `test_should_add_story'
    
      3) Failure:
    test_should_indicate_logged_in_user(StoryControllerTest) [./test/functional/stor
    y_controller_test.rb:100]:
    <#<User:0x3bb2da8
     @attributes=
      {"name"=>"Patrick Lenz",
       "id"=>"1",
       "password"=>"sekrit",
       "login"=>"patrick",
       "email"=>"patrick@lenz.sh"}>> expected but was
    <nil>.
    
      4) Error:
    test_should_reject_missing_story_atribute(StoryControllerTest):
    NoMethodError: You have a nil object when you didn't expect it!
    You might have expected an instance of ActiveRecord::Base.
    The error occurred while evaluating nil.errors
        ./test/functional/story_controller_test.rb:49:in `test_should_reject_missing
    _story_atribute'
    
      5) Failure:
    test_should_show_new(StoryControllerTest)
        [C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_co
    ntroller/assertions/response_assertions.rb:26:in `assert_response'
         C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_co
    ntroller/assertions/response_assertions.rb:18:in `assert_response'
         ./test/functional/story_controller_test.rb:25:in `test_should_show_new']:
    Expected response to be a <:success>, but was <302>
    
      6) Failure:
    test_should_show_new_form(StoryControllerTest)
        [C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_co
    ntroller/assertions/selector_assertions.rb:281:in `assert_select'
         ./test/functional/story_controller_test.rb:32:in `test_should_show_new_form
    ']:
    Expected at least 3 elements, found 0.
    <false> is not true.
    
      7) Error:
    test_should_store_user_with_story(StoryControllerTest):
    NoMethodError: You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.user
        ./test/functional/story_controller_test.rb:115:in `test_should_store_user_wi
    th_story'
    
    22 tests, 45 assertions, 4 failures, 3 errors
    rake aborted!
    Command failed with status (1): [C:/InstantRails/ruby/bin/ruby -Ilib;test "...]
    
    (See full trace by running task with --trace)
    
    C:\InstantRails\rails_apps\shovell>
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  14. #39
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Well it seems the big dump of errors is too much so maybe taking them one at a time might help out.

    As the first error is in the account_controller_test.rb file and all the other errors are in story_controller_test.rb maybe dealing with that one first is a good approach.

    The test
    Code:
      def test_should_redirect_after_login_with_return_url
        post :login, { :login => 'patrick', :password => 'sekrit' }, 
            :return_to => '/story/new'
        assert_redirected_to '/story/new'    
      end
    The results
    Code:
      1) Failure:
    test_should_redirect_after_login_with_return_url(AccountControllerTest)
        [C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_co
    ntroller/assertions/response_assertions.rb:86:in `assert_redirected_to'
         C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_co
    ntroller/assertions/response_assertions.rb:35:in `assert_redirected_to'
         ./test/functional/account_controller_test.rb:43:in `test_should_redirect_af
    ter_login_with_return_url']:
     response is not a redirection to all of the options supplied (redirection is <{"
    controller"=>"story"}>), difference: <{"action"=>"new"}>
    I highlighted in red the area that seems to be indicating where the trouble is. My fixtures are "users" and the setup hasn't changed.

    It seems to be telling me that everything is working as expected however, instead of being redirected_to '/story/new', it is being redirected to '/story' with an action of "new".

    I'v efiddled around with the code quite a bit to no avail. If I change it so that the :return_to => '/story' and the assert_redirected_to '/story' I get a similar error but difference: <{"action"=>"index"}

    Any ideas?

    Thanks

    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  15. #40
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Try assert_redirected_to '/story/index' and :return_to => '/story/index'. Maybe you just have to be more explicit in your testing.

  16. #41
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Part I Somewhat Resolved...

    Hey Vinnie.

    Actually, I think the test might be flawed in how it expects the redirect to work or perhaps it is acting differently on a Windows dev machine as opposed to the OSX machine the text was written on.

    This particular test is to test whether the login + redirect will redirect the browser to the '/story/new' page. In live browser testing this does work as expected. It's only in functional testing that it doesn't. There are a few other threads in the Ruby forum that indicate others are having the exact same trouble and from the looks of things they are also using InstantRails on Windows with :
    Ruby version 1.8.4 (i386-mswin32)
    RubyGems version 0.8.11
    Rails version 1.2.2
    Active Record version 1.15.2

    The login code is the following:
    Code:
    class AccountController < ApplicationController
    
      def login
        if request.post?
          @current_user = User.find_by_login_and_password(params[:login], params[:password])
          unless @current_user.nil?
            session[:user_id] = @current_user.id
            unless session[:return_to].blank?
              redirect_to session[:return_to]
              session[:return_to] = nil
            else
              redirect_to :controller => 'story'
            end
          end
        end
      end
    
      def logout
        session[:user_id] = @current_user = nil
      end
    end
    The test in the text goes like this:
    Code:
      def test_should_redirect_after_login_with_return_url
      post :login, { :login => 'patrick', :password => 'sekrit' },
          :return_to => '/story/new'
        assert_redirected_to '/story/new'
      end
    To be more explicit the last line could be:
    assert_redirected_to :controller => 'story', :action => 'new'

    The problem seems to be that :return_to => '/story/new' does not do anything in the test harness. I can pull that statement right out of the test and it makes absolutely no difference. Once the login has completed the code is directed to 'story'. That's all.

    In order to return the code somewhere useful, I found one of the other threads about this problem mentioned using: 'return_to' => '/story/new'

    This works! I was able to test with:
    assert_redirected_to :controller => 'story', :action => 'new'
    and: assert_redirected_to '/story/new'

    I'm still baffled about it because I thought :return_to and 'return_to' would do the same thing. Maybe it's a problem specific to the Windows version or this particular rails configuration.

    I still have to figure out the other problem and that is the protected methods for post_with_user and get_with_user
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  17. #42
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by awasson View Post
    Hey Vinnie.

    Actually, I think the test might be flawed in how it expects the redirect to work or perhaps it is acting differently on a Windows dev machine as opposed to the OSX machine the text was written on.

    This particular test is to test whether the login + redirect will redirect the browser to the '/story/new' page. In live browser testing this does work as expected. It's only in functional testing that it doesn't. There are a few other threads in the Ruby forum that indicate others are having the exact same trouble and from the looks of things they are also using InstantRails on Windows with :
    Ruby version 1.8.4 (i386-mswin32)
    RubyGems version 0.8.11
    Rails version 1.2.2
    Active Record version 1.15.2

    The login code is the following:
    Code:
    class AccountController < ApplicationController
    
      def login
        if request.post?
          @current_user = User.find_by_login_and_password(params[:login], params[:password])
          unless @current_user.nil?
            session[:user_id] = @current_user.id
            unless session[:return_to].blank?
              redirect_to session[:return_to]
              session[:return_to] = nil
            else
              redirect_to :controller => 'story'
            end
          end
        end
      end
    
      def logout
        session[:user_id] = @current_user = nil
      end
    end
    The test in the text goes like this:
    Code:
      def test_should_redirect_after_login_with_return_url
      post :login, { :login => 'patrick', :password => 'sekrit' },
          :return_to => '/story/new'
        assert_redirected_to '/story/new'
      end
    To be more explicit the last line could be:
    assert_redirected_to :controller => 'story', :action => 'new'

    The problem seems to be that :return_to => '/story/new' does not do anything in the test harness. I can pull that statement right out of the test and it makes absolutely no difference. Once the login has completed the code is directed to 'story'. That's all.

    In order to return the code somewhere useful, I found one of the other threads about this problem mentioned using: 'return_to' => '/story/new'

    This works! I was able to test with:
    assert_redirected_to :controller => 'story', :action => 'new'
    and: assert_redirected_to '/story/new'

    I'm still baffled about it because I thought :return_to and 'return_to' would do the same thing. Maybe it's a problem specific to the Windows version or this particular rails configuration.

    I still have to figure out the other problem and that is the protected methods for post_with_user and get_with_user
    no, the problem with :return_to and 'reutrn_to' is the same on my linux machine and i also have resolved with the string 'redirect_to' instead of the symbol version. I also still have the problem of the protected methods....if i put those methods at the end of the file (like it should be 'cause everything following the protected keyword is a protected method) i have some errors 'cause the program doesn't find them but if i put those protected method at the top i have also other problems...

  18. #43
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Interesting problem with the protected methods and again I think there is a problem with the actual methods as they are written as opposed to where they are.

    The methods:
    Code:
    protected
      def get_with_user(action, parameters = nil, session = nil, flash = nil)
        get action, parameters, :user_id => users(:patrick).id
      end
      
      def post_with_user(action, parameters = nil, session = nil, flash = nil)
        post action, parameters, :user_id => users(:patrick).id
      end
    If I run the tests with them either as public methods or at the bottom of story_controller_test.rb I get 3 failures and 3 errors. However, if I modify the methods and remove the '= nil' part I get 6 errors leading me to believe that the methods are available but are just not doing what we want them to do.

    I've got work to do right now but when I have the time, I'm going to rewrite the methods in such a way that they do what they're supposed to (I hope).
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  19. #44
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyway i think those methods should go at the bottom of the file 'cause every method that follows the protected keyword becomes a protected method and that is not what we want.

  20. #45
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Skyblaze View Post
    anyway i think those methods should go at the bottom of the file 'cause every method that follows the protected keyword becomes a protected method and that is not what we want.
    Yep, or you can put "public" or "private" before any methods that come after your protected ones to "reset" scope.

  21. #46
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia View Post
    Yep, or you can put "public" or "private" before any methods that come after your protected ones to "reset" scope.
    oh yes that is right

  22. #47
    SitePoint Zealot atetlaw's Avatar
    Join Date
    Feb 2007
    Location
    Melbourne, Australia
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi everyone,

    We've been investigating some of the issues with this book reported in the forum and via the SitePoint contact form and have made a significant update to the errata page. I highly recommend visiting the errata page and downloading the code archive again.

    Of course if you have any problems please let us know.

    Cheers,
    Andrew

  23. #48
    SitePoint Enthusiast stef686's Avatar
    Join Date
    Aug 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I seem to be having an odd problem with the login page html on page 240. I've downloaded the code archive and checked the latest errata but still doesn't work, I don't know if there is an error in my controller that might be causing it?

    The odd thing is the form isn't showing at all. I am getting the application html (header, footer, layout etc) but no login form is being displayed. Here's my code, if anyone has any suggestions I'd be very greatful!

    login.rhtml
    Code:
    <% form_tag do %>
      <p>Please log in.</p>
      <p>
        <label>Username:</label>
        <%= text_field_tag 'login' %>
      </p>
      <p>
        <label>Password:</label>
        <%= password_field_tag 'password' %>
      </p>
      <p><%= submit_tag 'login' %></p>
    <% end %>
    account_controller.rb
    Code:
    class AccountController < ApplicationController
    
      def login
      	if request.post?
      		@current_user = User.find_by_login_and_password(params[:login], params[:password])
      		unless @current_user.nil?
      			session[:user_id] = @current_user.id
      			redirect_to :controller => 'story'
      		end
      	end
      end
    
      def logout
      
      end
      
    end


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
  •