Chapter 7 ("Sign up") of the Ruby on Rails Tutorial book is out
railstutorial.org
railstutorial.org
$ <fix problem>
$ git commit -am "Fixed problem"
$ deploy tutorial
This generates the HTML and builds the PDF from the same source, and then pushes them both up to Heroku. It's very satisfying. :-)RailsTutorial, like Ruby and Rails, just feels right.
-- Fred
If I might suggest one improvement: I'd change @title with content_for. A class attribute needlessly messes View and Controller.
EDIT: Come to think of it, this might make for a good exercise.
def create
@user = User.new(params[:user])
@title = "Sign up"
render 'new'
end
So the end user can mess around with the form, add is_admin=1 to the other CGI params and end up with an admin account. (Or similar.) Fabulous.(1) The book uses test-driven development for the most part; the snippet you pasted is just enough to get the "failed signup" test to pass, and is not the full implementation. (2) The code you copied doesn't even save the user, so there's no potential security breach at this point. (3) There's no admin attribute yet. (It's coming in Chapter 9.) (4) The User model is protected by attr_accessible in any case, as discussed in Chapter 5 (http://www.railstutorial.org/chapters/modeling-and-viewing-u...). There's no way to tell from inspecting a controller action whether or not there's a security breach at the model level.
N.B. Just yesterday I exchanged notes with Yehuda Katz on this very subject; he and Carl Lerche both agree that Rails should close the attr_accessible security hole by default, much as Rails 3 now escapes the output of Embedded Ruby by default. My hope is that we'll see this implemented in Rails 3.x, for some value of x.