DISQUS

DISQUS Hello! e168f08 is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Protected: Downloads

Started by xertroyt · 9 months ago

No excerpt available. Jump to website »

33 comments

  • Where is the zip file with assignment 1? I am so confused
  • If you look at the page above, there is a heading that says: "Assignments."

    Under that there is a bullet item that says "Assignment 1."

    To the right of that, there is a link that says: "ZIP" -- click on that.
  • Slides 60 and 63 for lecture 2 have the wrong contents in the Jruby/irb text box.

    Also: I can advance to the next slide, in Firefox, by pressing the space bar, or (as I discovered to my annoyance, when switching between windows) by clicking anywhere on the slide except in the code box. There must be a relatively easy way to go BACK one slide, other than calling up the contents and finding the right slide number. I can't find it, but John appeared to be using it during the lecture. Any tips on how to do this?
  • You should be able to hit the back arrow to go back.

    I will look at slides 60 and 63. Note that I mentioned that sometimes you have to close the browser, and then double-click on the file all over again.
  • Back arrow to go back doesn't work for me, but strangely my page-up key does.

    Slides 60 and 63 turn out to be okay, it's just the bug in the application, and does fix itself when I close Firefox and re-open the file.
    (Note that double-clicking on the file only works if Firefox is your default browser: otherwise you need to either "Open With", or open Firefox and then do File->Open to open the slides)
  • My password is somehow not getting accepted. What should I do?
  • You shouldn't be using your personal password. You should be using the common password for this page, that was announced in the first lecture.
    That password is still working, as of a few minutes ago.

    But some time in the next few days, the password to this page will change to a new user/password combination that John announced in last night's lecture (October 1).
  • Can you please post the slides from lecture 4? It was really hard to follow the video without the slides
  • I just posted a fresh version of the ZIP file that has the HTML lectures -- there are a number of modified slides, and an additional slide regarding the mistake I made where I included a module and was surprised that a method in the target class wasn't overridden.
  • As of 10/12/2008 at 4:25 PM, which is the date on "lecture4.html" in the ZIP file I downloaded, slide 35 doesn't match the slide used during the lecture.
    The line "class Person; end" directly above class Player is missing, and class Player is not a subclass of Person. The not-very-usable slides being served with the video do contain the Person class. (I've checked the HTML source in emacs to make sure that it's not the Slidy application acting up).
  • Yes -- I removed it. I neglected to add "modified slide" to that one, and added the remark to the slide with the image.

    From slide to slide, JRuby keeps the class cached, and since I had earlier defined the class without a superclass of Person, the example wasn't running properly when I later defined it with a superclass.
  • The link to the "cycle" app gets a 404 error.
  • Fixed.

    I had created that ZIP at work -- the rake "package" task uses the user's login name, and at work I'm jnorman while at home I'm jgn -- and I had just changed the version number in the file name.
  • I have a question about LinkWizz... maybe I missed something in lecture. Not sure.

    I'm going through the code and playing around with it. When I enter a new user, it looks like the user_controller code:

    @user = User.find(:first, :conditions => params[:login])

    # If there wasn't a user, create one
    if !@user
    @user = User.new(params[:user])
    if @user.save
    flash[:notice] = 'User created.'
    else
    flash[:notice] = 'Couldn\'t register user.'
    # We return at this point, so that the POST will
    # complete, and views/users/login.rhtml will be
    # used, which has all of the validation info.
    return
    end
    end

    should be executed. But I do not see any value being populated in the params[:login]. The site always logs in as 'John'. What am I missing?

    Mike
  • Mike,

    Could you provide some steps to reproduce:

    1. Start not logged-in
    2. Enter John as the user

    etc.
  • Mistated the above a bit. Meant to say it looks as if @user is always true, no matter what login information is typed into the login field.
  • If you type in "foobar" as the login name, User.find(:first, :conditions => params[:login]) should return nil, that is, nil would be assigned to @user

    So then we effectively say . . .

    if !nil

    (!nil evaluates to true)

    i.e., if there is no user by that name, create one.

    OK?
  • OK... here's what I am doing

    did the rake db:migrate
    running the ruby script/server
    browsing to http://localhost:3000/ using Firefox v 2.0.0.18

    Get the login page with Login or Register above the text box
    type John in the text box
    press enter

    logs in... indicates logged in as john in upper right menu bar
    shows default google news bookmark

    click on logout
    flash[:notfiy] places 'Logged out' above the text entry box (and the label of Login or Register)

    This time I type in 'test'
    logs in... indicates logged in as john in upper right menu bar
    shows default google news bookmark

    I would have expected two things based upon a read of the code:

    1.) a flash[:notice] showing 'User created.'
    2.) a logged in as test in the upper right corner of the menu bar

    When I try to debug it, I see that !@user always evaluates to false.
    So, I throw a flash[:notice] = @user in after the find, and I see that @user is being set to '#' so it is not nil

    Don't know why I see john as the user... confusing me

    Mike
  • I think you've found a bug. This bit from what you say:

    click on logout
    flash[:notfiy] places 'Logged out' above the text entry box (and the label of Login or Register)

    This time I type in 'test'
    logs in... indicates logged in as john in upper right menu bar
    shows default google news bookmark

    -----

    Notice that UserController#logout says: reset_session - that is supposed to kill the session, so that, e.g., session[:login] should not have a value.

    Let me get back to you on that, with an explanation or a fix.
  • Thanks. Also, I see now that regardless of what I place into the login field, the code below always evaluates to john...

    @user = User.find(:first, :conditions => params[:login])
    flash[:notice] = @user.login # outputs 'john'
  • I haven't looked at the code yet, but I did notice, with just a little playing with the application, that whatever name I type in to the login field, the next page always tells me I'm logged in as "John"
  • Oops. I meant to type "john" (no uppercase J)
  • See the discussion with "philadelphia" below -- the problem seems to be that the session isn't getting cleared out.

    I will provide an explanation or a fix tonight: It's possible that something subtle has changed between Rails 1.x and 2.1 regarding session handling.
  • But this is happening on my own machine, with no previous session, so session handling seems unlikely.
    Digging around, I see that there's only one row in the "users" table. Using script/dbconsole, I update that row so that the login column has the value 'herbert'. Closing my browser and restarting it, I attempt to login with the name "Morris", and the system tells me I'm "Logged in as herbert". [I am not herbert].

    I suspect there's something wrong with your find, which is finding the first row in the database table, regardless of the string entered in the form.
  • I think I've found the problem. I added some debugging code to UsersController#login, just after the call to User.find:

    if @user
    puts "found user #{params.login}"
    puts "User's name is #{@user.login}"
    end

    to see what this code is getting from the database.
    Logging in again, I see, amidst lots of other output,

    found user
    User's name is herbert

    Note that there's nothing after "user" in "found user". For some reason, params[:login] is blank.
    Looking at view/users/login.html.erb, we see
    <%= form.text_field :login
    so there ought to be a :login entry in the hash.

    but viewing the source of the HTML as seen by the browser, we see the corresponding HTML form field has the attributes

    id="user_login" name="user[login]" because this is a "<% form_for :user"
  • So the fix is to change the call to User.find to

    User.find(:first, :conditions => params[:user])

    where params[:user] is a hash, containing the key :login

    since there's no params[:login], the existing call

      User.find(:first, :conditions => params[:login])

    calls User.find with no conditions, and always returns the first row in the users table.
  • Yup... that works...

    Mike
  • Thanks.

    I now see where this bug crept in.

    In the original version (last year) of LinkWizz, the e-mail address was always used (rather than a username / login name). Somewhere in the refactoring I switched the :conditions => specification, and, obviously, did it wrongly.

    When I get home I will check to make sure that this issue hasn't propagated elsewhere (e.g., to CCC).

    I actually dumbed down the user controller in LinkWizz and CCC in order to make the switch (will I will be showing) to acts_as_authenticated more dramatic. But as you can see, I dumbed it down too much.
  • I am running system/console in C:\aaa\rubyStuff2\e168-assignment3-milestone-3-30000

    I am having trouble writing a sql select to get units.id given observation_kinds.id. Here is the ActiveRecord code that I am using.

    >> X = Measurement.find(:all, :conditions => "observation_kinds.id = 6", :include => [:observation_kinds, :units])

    X appears to be an Array but I am having difficulty navigating X. What little bit that I can see does not include units.
    Second, I would really like to see the sql code used to get whatever is in X.
    Setup.rb from a previous assignment (I assume for use without Rails; just ActiveRecord with ruby) does not provide me sufficient clues to see the sql.
    Given the number of hours I have spent on this, I am ready for some hints.
    Thanks
    Brian
  • You can iterate through the resutls . . .

    x.each { |item| ... }

    Incidentally, X should not be capitalized. If you do that, it's a constant.

    As well, you probably want to put in a variable id for where you have the literal "6" -- this is a big, big "no no." Review section 17.5 of AWDR and take a look at the ? syntax for conditions.
  • Thank you for the sympathetic ear. The thing I was missing was the 1:n relation between measurements and units.

    I was using the equivalent of x[0].units.id rather than x[0].units.first.id .

    Having to explain the problem helps clarify the issues in my own head.

    I am still curious about the sql code view though.
  • John,

    I am looking at booksindex for an example of nested routes. I see where the nesting is declared in the routes file. But the path names don't seem to reflect nesting. (Though they obviously work.)

    As close as I understand, without any special configuration, the route parameter on the for index.html.erb in the index_entries view folder, would be, for example, <td><%= link_to 'Show', book_index_entry_url(@book, index_entry) %></td>. With @book providing the book ID, and index_entry providing the index_entry id.

    Is that correct?

    I know there are shortcuts to reduce the name parameter, but in order to understand it, I am trying to figure out what the actual syntax should be for route parameters.

    Is it possible to see a version with routes fully flushed out, in a non-shortcut way, just to get the flavor of the correct syntax?
  • I'm not sure why you would want a link to a specific entry for a book? More typical are:

    -- Let me see the book associated with this index entry:

    <%= link_to 'Book for this index entry', book_path(@index_entry.book) %> |
    (put in views/index_entries/show.html.erb

    -- Or, let me see the index entries for this book:

    <%= link_to 'Index entries for this book', book_index_entries_url(@book) %> |
    (put in views/books/show.html.erb

Add New Comment

Returning? Login