small medium large xlarge

Generic-user-small
23 May 2008, 06:57
Anders Nehlin (12 posts)

Hi, Great book and a wonderful tutorial. I have followed it tightly but ran into a problem though on page 164. When I tried to open http://localhost:3000/login/add_user I got the following error message: NoMethodError in LoginController#add_user undefined method `authorize’ for #

Thanks in advance for your help!

Best regards, Anders

Samr_small_pragsmall
23 May 2008, 12:20
Sam Ruby (634 posts)

Unfortunately, you have gone past the point where the material has been updated for Rails 2.0. Check the “Preface to the Third Edition” on page 15 for details. The color of the bars on the top and bottom of the page also provide a visual clue. Chapter 11 will be updated in the next beta, which should be out in under a week.

Generic-user-small
23 May 2008, 12:40
Anders Nehlin (12 posts)

Thanks for your response.

I have to wait until then I guess.

Xit_pragsmall
25 May 2008, 18:41
osagie uwaifo (8 posts)

Anders try restarting your application. If that does not work, create a dummy controller like the way the store controller was created. Access the dummy controller, then access the login controller. That should work. That is what i did.

Generic-user-small
27 May 2008, 16:51
Anders Nehlin (12 posts)

Hi osagie,

Thanks for your help! Unfortunately, I am a newbie so I don’t understand what you mean by “Access the dummy controller, then access the login controller”. I would appreciate if you could explain the exact steps for me. Thanks in advance.

Generic-user-small
28 May 2008, 21:00
Anders Nehlin (12 posts)

Hi guys,

I have used the downloaded files in chapter 11 of the latest version (28 May) but I still got the same error message.

It is very frustrating to be stuck and depending on your help since I am a newbie…. Appreciate all help.

Thanks in advance!

Samr_small_pragsmall
28 May 2008, 22:46
Sam Ruby (634 posts)

I understand and appreciate your frustration. We simply are going to have to debug this together, and since I can’t actually see your machine, that will by necessity be a slow process. But rest assured that I’m not going anywhere, and intend to see this through.

But first we have to back up. You say that you downloaded the files and are seeing the same error message. One of those can’t be true. How do I know that? The error message references an add_user method. There is no add_user method defined in the 28 May version of the book. This method is purportedly in the login controller. Once again, there is no login controller in the 28 May version of the book. The user add functionality has been replaced by the new method in the “users_controller”:http://media.pragprog.com/titles/rails3/code/depot_p/app/controllers/users_controller.rb

What I need you to do here is to back out the work that you did based on prior betas, and to pick up once again with the start of chapter 11 and try to reproduce the results.

If you leave comments as to your progress, I will check back and try to make helpful suggestions.

How does that sound?

Generic-user-small
29 May 2008, 13:21
Anders Nehlin (12 posts)

Sounds fine with me!!

Thanks a lot.

Generic-user-small
29 May 2008, 14:28
Donald Craig (2 posts)

I think that the problem may be on page 165 of B1.2, where it says to visit the URL:

http://localhost:3000/login/add_user

I believe that it should be:

http://localhost:3000/users/new

(The figure on the same page is outdated too.)

Generic-user-small
29 May 2008, 19:03
Anders Nehlin (12 posts)

Hi guys,

Now I have messed up my store by trying to replace files from the code-folder. When I browse to http://localhost:3000/store it goes to http://localhost:3000/admin/login instead. And when I go to http://localhost:3000/login/add_user I got the following error message: Routing Error No route matches “/login/add_user” with {:method=>:get}

Still stuck but hopeful..

Samr_small_pragsmall
29 May 2008, 22:11
Sam Ruby (634 posts)

Donald: you are correct, and I will fix that (both the text and the image) in the next beta.

Anders: it actually sounds like you are not messed up. /store should redirect to /admin/login and /login/add_user should be a routing error. With B1.2, the intended way to create a new user is with /users/new.

Generic-user-small
30 May 2008, 11:43
Anders Nehlin (12 posts)

Hi Sam,

When I try to create a new user at http://localhost:3000/users/new it redirects to http://localhost:3000/admin/login, so I can’t register myself.

What shall I do? How do I get access to my store again?

Generic-user-small
30 May 2008, 13:58
James West (104 posts)

I am having the same problem.

After adding the changes to the application model I am redirected to the login page whenever I try to access anything other than the catalogue.

I know this is the expected behaviour and I have set up a user called test but whenever I enter the user into the login screen and press login I just get the login screen re-displayed with no indication as to why so it looks like the redirect is failing.

I took my code to the next stage and added the “friendlier log in” stuff but to no avail.

The strange thing is that if I comment out the before_filter code in the application.rb the login works and I am directed to the admin page with the order details.

My def authorise in the admin looks like this

  def authorize
    unless User.find_by_id(session[:user_id])
      session[:original_uri] = request.request_uri
      flash[:notice] = "Please log in"
      redirect_to :controller => :admin, :action => :login
    end
  end

Also in the admin controller my login looks like this

  def login
    session[:user_id] = nil
    if request.post?
      user = User.authenticate(params[:name], params[:password])
      if user
        session[:user_id] = :user.id
        uri = session[:original_uri]
        session[:original_uri] = nil
        redirect_to(uri || { :action => "index" })
        flash.now[:notice] = "Re-directed"
      else
        flash.now[:notice] = "Invalid user or password"
      end
    end
  end

And none of the flashes appear anywhere to indicate that I have an incorrect login detail.

I know I must be missing something but can’t think what and have been through the admin set up twice now so I am kinda stuck now too and any pointers would be appreciated.

Samr_small_pragsmall
30 May 2008, 15:13
Sam Ruby (634 posts)

Anders: skip ahead for a moment to page 174. :-)

James: I suspect that the controller isn’t setting session[:user_id]. Can you check the login method in app/controllers/admin_controller.rb ?

update

The problem is what session[:user_id] is set to. Please change:

session[:user_id] = :user.id

to:

session[:user_id] = user.id
Generic-user-small
30 May 2008, 15:11
James West (104 posts)

Hi thanks Sam.

I thought pretty much the same thing which is why I included app/controllers/admin_controller.rb login code in my post.

I have checked the book and checked against the code you have on-line and the only real difference is the friendlier login code I have added. But the problem existed before I added this.

Really confused :-)

Generic-user-small
30 May 2008, 15:16
James West (104 posts)

Hi, Just reversed the friendlyier login in code back out and it all works now.

Sorry.

Generic-user-small
06 Jun 2008, 19:31
Anders Nehlin (12 posts)

Hi Sam,

I have not been working with the depot project for a while because I have been struggling with my wireless internet on my laptop. Anyway, now it works so I can get back to the depot project, BUT now I have another problem: I can not browse to the localhost. Do you know if the software for my wireless internet could interfere in some way?

Appreciate your help!!

Generic-user-small
07 Jun 2008, 09:58
Anders Nehlin (12 posts)

Hi again,

I forgot to say that I use ubuntu as the OS.

Samr_small_pragsmall
11 Jun 2008, 13:35
Sam Ruby (634 posts)

If browsing to http://127.0.0.1:3000/ works, I would check your /etc/hosts file to make sure that it maps localhost to 127.0.0.1.

David_pragsmall
13 Jun 2008, 04:08
David Schwartz (26 posts)

OK, I’ve got the B1.2 printing and had the same confusion. Using users/new worked (although it’s not nicely formatted as shown in the PDF). Am I free to continue? When will the next rev be available that has been updated for R2.0.2?

I guess I’ll go and work on my Mac configuration.

David

Samr_small_pragsmall
13 Jun 2008, 14:07
Sam Ruby (634 posts)

Given that we are talking about a book that will be published in print form October-ish and people will be buying in stores next year, my focus is to keep up with the latest Rails. Starting with B1.3, this means Rails 2.1.

The two differences that were encountered in the upgrade were in Migration (the names of the migration files changed, and Rails internally keeps track of exactly which migrations have been applied, and not merely the last one) and a minor formatting change in the edit scaffold produced by generate/scaffold.

David_pragsmall
13 Jun 2008, 23:52
David Schwartz (26 posts)

Meaning that there’s really nothing else we have to worry about?

Samr_small_pragsmall
15 Jun 2008, 14:40
Sam Ruby (634 posts)

I don’t believe so. In developing B1.0, B1.1, and B1.2, I had been testing under both 2.0.2 and rails edge. B1.3 was updated so that the text matched 2.1, but the only substantive changes involved were the ones I mentioned above.

You must be logged in to comment