On 18 March 2010 13:43, ES <[email protected]> wrote: > I'm trying to create a data entry form but getting an error when it > sumbmits. I am using an hash to get the names of the fields definied > in the controller's "new" function: > > def new > �...@thing = thing.new > �...@columns = Hash.new > > �...@columns['thing_general'] = [ > ["title","name"], > ["number","num"], > > etc... > > and then I access it in the object's new.html.erb: > > <% for c in @columns['thing_general'] do %> > <tr> > <td class="name"> > <label for="<%=c.first%>"><%=c.first%></label></td> > <td> > <input id="<%=c.second%>" name="thing[<%=c.second > %>]"type="text" /></td> > </td> > > the first time I load the page, the correct form displays but then > when I click submit, I get this error : > > You have a nil object when you didn't expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[] > > Extracted source (around line #38): > > 35: <tr><td><hr/></td></tr> > 36: > 37: <tbody> > 38: <% for c in @columns['thing_general'] do %> > 39: <tr> > 40: <td class="name"> > 41: <label for="<%=c.first%>"><%=c.first%></label></td> > > > > why would it get a nil object when I submit the form (after working > the first time) and why is it trying to load the same page after > submitting?
I presume that when you click it is calling a controller action, then for whatever reason rendering the page again, but this time @columns is not setup, hence the error. Have a look at the action called by the submit and see what you have told it to do. Also have a look in development.log and you may get a clue. Guessing at what the code may do, possibly the submit requests a save that fails so you are re-rendering the page to allow the user to make a correction, but you have not setup @columns. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

