@Ellis:
In your form_for, try :html => { :method => “put” } instead of just
:method
=> :put.
@David:
I admire your book, *Ruby for Rails: Ruby techniques for Rails
developers, *it
was the first and only Ruby/Rails book I have read cover to cover.
Taught me
a lot of interesting things.
"
One reason, at least, is that #create always returns the instantiated
object, whether that object got saved or not. So you can’t use it in
an “if” test (whereas you can use “if @thing.save”). You can of course
do “if @thing.valid?”, but that’s still a slightly oblique way of
determining whether or not it was saved."
But .create! raises an Exception. This exception could either be an
ActiveRecord::RecordNotSaved, or an ActiveRecord::RecordInvalid,
depending
on if the model does not have or has a validate method defined on it,
respectively.
I use .create! in my code, but .save with an if works just as well 
def create
@school = School.find(params[:school_id])
@course = @school.courses.create!(params[:course])
flash[:notice] = “Course was successfully created.”
redirect_to school_course_path(@course)
rescue ActiveRecord::NotSaved, ActiveRecord::RecordInvalid => @e
flash[:notice] = “Course could not be created.”
render :action => “new”
end
The @e instance variable will either be “ActiveRecord::NotSaved” or
whatever
errors are thrown from the validate method. I rescued both, just in
case.
On Dec 6, 2007 9:40 AM, Ellis B. [email protected]
wrote:
–
Posted via http://www.ruby-forum.com/.
–
Ryan B.