From: Jacob Fugal Date: 2005-12-06T06:49:29+09:00 Subject: Re: a todo list On 12/5/05, gregarican wrote: > steven masala wrote: > > def add_tasklist > > tasklist = Tasklist.new > > tasklist.attributes = @params["new_tasklist"] > > > > > > if tasklist.save > > redirect_to(:action => "list") > > else > > render_text"could not add" > > end > > You closed your controller method with def...end but not the > conditional if...else...end. Add an extra 'end' to the bottom of your > code and you should be okay. Well not necessarily at the end of the code. It should be added in place right after the else block (the way I indicated in my reply to your other post, Steven). To see why you can't just blindly put it at the end of your code, imagine his class actually looks like the following: class MyController def add_tasklist tasklist = Tasklist.new tasklist.attributes = @params["new_tasklist"] if tasklist.save redirect_to(:action => "list") else render_text"could not add" end def other_action # body of other action end end Ruby sees the first end after the else as belonging to the if/else. The definition of other_action then ends up being part of the body of add_tasklist, and the final end closes the definition of add_tasklist. The class remains unclosed and that's what causes the syntax error. If you add an "end" at the end of the file, you close the class and remove the syntax error, but the code is still broken, because the definition of other_action is still local to the body of add_tasklist, obviously not the desired functionality. Jacob Fugal