Screencast demoing “restful authentication”
December 2, 2008 | Filed Under Announcements | Comments
I’ve posted a screencast (in two parts) taking you through the steps to create an application with “restful authentication.” At this point, it shows how to use a plugin to mange registering users and logging them in; as we learn more about REST, this plugin will help us to keep our RESTful service secure.
Note as well that this is one of the options for the final project . . .
You can find the screencast on the “Screencasts” page.
There will be a followup screencast where I will refactor an existing application to use this plugin.
MetricsMine: Fixed bug
November 28, 2008 | Filed Under Uncategorized | Comments
In your implementations of MetricsMine, after an edit is made to a Unit, Measurement, or MeasurementKind, you should redirect to the index action for that controller.
Originally, in the reference implementation, this was handled by an action called list. The index action would delegate to list.
In order to reduce the amount of code you have to implement, at some point I got rid of list, and put its functionality in index — but I forgot to fix the redirects, which were going to list, not index.
This is now fixed in the reference implementation. Again, in your implementation, after a instance of a particular model is edited (i.e., updated with the “update” action) you should redirect to the index action.
That’s it.
John
datetime_select (used in Assignment 3)
November 25, 2008 | Filed Under Uncategorized | Comments
Note:
The datetime_select helper will accept the option :include_seconds
This is important for getting the date/time selector to see all time elements down to the second. It can be seen here:
http://metricsmine.plugh.org/observation_sets/show/1
It really isn’t that necessary for the application, but it is irritating if you are trying to duplication the operation of the “reference” implementation.
It is possible that eventually you would guess that this option is possible, because datetime_select is extremely similar to time_select, and the docs for time_select describe :include_seconds (see http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M001479).
John
Assignment 3, Milestone III available
November 15, 2008 | Filed Under Announcements | Comments
Folks,
The description is here: http://e168f08.plugh.org/assignments/assignment-3-milestone-iii/
And the download is on the downloads page.
Enjoy!
Remember, due Sunday, Dec. 7.
John
Assignment 3, Milestone II posted
November 14, 2008 | Filed Under Announcements | Comments
Folks,
I’ve posted the list of finds for Assignment 3 on the “Assignments” page. As I mention there, it’s quite brief, because the MetricsMine app does not lend itself to complicated use cases. Have fun. Full version of Assignment 3 is almost done, I just need to pick out the views you will need to implement. (I’m having a bit of a “perfect storm” with time scheduling right now, I’m afraid!)
John
Slightly updated version of the “crud” app on downloads page
November 14, 2008 | Filed Under Rails | Comments
I wanted to note a detail about what happens when validation fails on model objects managed by a form; and how the form gets re-presented to the user.
The upshot of what I am about to describe is this: Make sure that all of the information the form needs is put back into the instance variables.
In the original version of the Student model, there were no validations - so a new Student would always get saved properly.
But let’s suppose that we add a validates_presence_of :last_name to the model. And let us suppose that the save fails because that field is left blank. Here’s what create looks like:
def create
@student = Student.new(params[:student])
if @student.save
redirect_to :action => :index
flash[:notice] = 'Student was successfully created.'
else
render :action => :new
end
end
Now here’s the problem: We’ve posted back to create, and because the save doesn’t work, we go to the else, which asks to render with the template associated with the new action. (Remember, incidentally, that this doesn’t mean execute the new action — it means only: Use the template associated with new.
However, one thing that is required for that form to work is for the @sections instance variable to be set up. This is used to get the available sections to show in the drop-down. I would urge you to add the validation and try to save a student with an empty last name. See the error? So, what we need to do is find all of those sections before rendering the template associated with new. In short, it should look like this:
def create
@student = Student.new(params[:student])
if @student.save
redirect_to :action => :index
flash[:notice] = 'Student was successfully created.'
else
@sections = Section.find(:all) # Important line!
render :action => :new
end
end
The previous version worked fine; but were we to have validations which result in the save failing, we would not be setting up the form properly.
I’ve uploaded a tweaked version of the “crud” app which you can get from the downloads page; both versions will work fine but I thought you should be aware of this important aspect of the form lifecycle.
Assignment 3, Milestone I
November 1, 2008 | Filed Under Announcements | Comments
I have posted Assignment 3 and have uploaded a ZIP that constitutes Milestone I of Assignment 3:
http://e168f08.plugh.org/assignments/assignment-3-2/
— and the ZIP is on the downloads page
Shortly there will be more “to dos” and fresh ZIPs for Milestones II and III. Milestone III - a complete webapp - is what you’ll be handing in on Nov. 23 Dec. 7.
The first two milestones are:
Milestone I: This is what the posted assignment and ZIP are about. For this milestone, you will create migrations and add validations and associations to models so that tests pass. If you’ve been reading along and watching the lectures, this should be about 2 hours of work; and, given that this is new to you, let’s double that for a more realistic appraisal for the amount of time it will take. I expect you to be done with it by Sunday Nov. 9. On Nov. 10 I will send around a ZIP that has the migrations, validations, and associations as I wrote them.
Milestone II: This will be a list of challenges to write finders against the database — all of which will be instrumental for Milestone III which will be the complete web app.
The final milestone is the actual web app, where we will hand out a skeleton of the app, and you will need to write certain key controllers and views. We will also run on the server (as we have done with linkwizz.plugh.org) a reference version of the assignment. Incidentally, there will be a written component to the final hand-in for Assignment 3. It will be lengthier than the writeup part of Assignment 2, and will ask you to answer questions about how you would expand the application in various ways.
This worked well last year — the only thing really missing is room for a lot of creativity, but that is what the final project is about.
I am also going to try to make you a screencast that shows me negotiating the project, making a rule or two pass. I think you will find this useful to understanding the work pattern.
Two requests:
(1) I know that some of you out there are jackrabbits who like to try and stuff done right away. If you do so, and have feedback for me, I’m all ears. These are not easy assignments to put together, and I would welcome any suggestions you’d have that would clarify the assignment description or the code bundle. On occasion students complain because we give out the code bundle in successive bundles, but there are almost always unanticipated difficulties owing largely to our own movement to the latest version of the framework.
(2) Look at your schedules. Right now the due date for Assignment 3 is Nov. 23 Dec. 7. Since I will be handing out the official schema on Nov. 10, that means you’ll have a day short of two weeks to do the assignment. I don’t like the idea of extending a due date over Thanksgiving, but in the interests of balancing the tempo of the course against the realities of lives and jobs, I’d like to know what you think about these deadlines. To be sure, there is an unknown factor for you, which is that you don’t know for sure how much work it’s going to be. But the staff and I will attempt to create the appropriate amount of work for that two-week period.
I think that’s it. For discussion, add your comments to the assignment #3 page.
John
Draft of Assignment 3 with the first milestone almost done
October 31, 2008 | Filed Under Uncategorized | Comments
I’ve posted a draft of #3 — the ZIP is coming. Have to do a bit more work and then it will be out.
The draft is here: http://e168f08.plugh.org/assignments/assignment-3-2/
Lecture 6 and migrations1 ZIP
October 23, 2008 | Filed Under Announcements | Comments
I’ve posted the PDF for Lecture 6 and the ZIP for the migrations1 example on the downloads page.
Assignment 2B (optional!) on Assignments page
October 21, 2008 | Filed Under Announcements | Comments
I’ve added a draft of Assignment 2B — which is optional — to the assignments page. This is done “cookbook” style, with a key portion for you to do on your own. It leverages a ZIP called e168-ar-skel-jgn-10000.zip which you can find on the downloads page.
I may tweak it a bit before Wednesday night.
Again, it’s optional. I believe, though, that after hearing the lecture Wednesday night and after studying the ar-skel download, you can get this down in less than an hour.