I have a model Area which has_many Streets. The Area has a couple of attributes of its own but mostly I want to be able to add/delete/update Streets for a particular Area, but all on one page rather than having a separate view for editing a Street. I''ve managed to get a form displayed with a row for each Street already assigned to the Area by using form fields with street[id][name], street[id][num_houses] etc. But when I send the form I don''t know how to get any validation errors reported. Errors on Area are nicely displayed with the red outlines - I think this is thanks to <%= error_messages_for ''area'' %> being included in the view. Can I get this to work for the multiple Street input fields as well? I''ve tried <%= error_messages_for ''street'' %> (You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occured while evaluating nil.errors) and <%= error_messages_for ''street[]'' %> (`@street[]'' is not allowed as an instance variable name) def update_area @area = Area.find(params[:id]) @streets = @area.streets unless params[:street].nil? Street.update(params[:street].keys, params[:street].values) end if @area.update_attributes(params[:area]) flash[:notice] = ''Area was successfully updated.'' redirect_to :action => ''edit_area'', :id => @area else render :action => ''edit_area'' end end Thanks so much in advance for any suggestions. -- Posted via http://www.ruby-forum.com/.
On Jan 23, 2006, at 6:39 AM, Michael Bannister wrote:> I have a model Area which has_many Streets. The Area has a couple of > attributes of its own but mostly I want to be able to add/delete/ > update > Streets for a particular Area, but all on one page rather than > having a > separate view for editing a Street. I''ve managed to get a form > displayed with a row for each Street already assigned to the Area by > using form fields with street[id][name], street[id][num_houses] etc. > But when I send the form I don''t know how to get any validation errors > reported. Errors on Area are nicely displayed with the red > outlines - I > think this is thanks to <%= error_messages_for ''area'' %> being > included > in the view. Can I get this to work for the multiple Street input > fields as well?error_ messages_for is not responsible for adding the red outlines-- its sole purpose is to dump out the error messages associated with an ActiveRecord object. In fact, it is highly recommended that you use your own method or replace error_messages_for because it is so ugly (imho). To answer your question, though, see http://www.ruby-forum.com/topic/ 52143. The topic is closely related, and then goes off-topic a bit towards your direction, so keep reading. Duane Johnson (canadaduane) http://blog.inquirylabs.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060123/6672c7f2/attachment.html
> To answer your question, though, see http://www.ruby-forum.com/topic/ > 52143. The topic is closely related, and then goes off-topic a bit > towards your direction, so keep reading.Many thanks - looks like what I''m after, and I''ll read it more thoroughly tomorrow! :-) -- Posted via http://www.ruby-forum.com/.