views:

20

answers:

1

Hello,

I have a form that the user is going to interact with, by updating, etc. The data is being pulled from the database, so that the user can see previous data and add new ones as well. So basically when I try to execute the code below, I get an error, saying that there is no method...

@display = Sales.find(:all, :conditions => ['year =?', _year])
render :partial => "display" #which renders the table that has the form in it.

<td><%= text_field 'display', 'price'%></td> #is the input field

I have price as a column in my database :S

Thanks for the help guys! Merry X-mas

+1  A: 

The display variable is an Array. You'll need to pass the results of the Sales.find in the :collection parameter of render partial:

@display = Sales.find(:all, :conditions => ['year =?', _year])
render :partial => "display", :collection => @display

That should render the partial once for each item that is returned by Sales.find

Adam Crossland
still doesn't work :S
You're being a big help.
Adam Crossland
sorry, I should be a bit more descriptive, it still gives the same error, by which I mean, it says that its an undefined method ... :S
Is is still reporting that the display object is an Array? If so, I would change the name up a bit; that could be confusing Rails. Everything is named display, and that could be a problem.Try:found_sales = Sales.find(:all, :conditions => ['year =?', _year])render :partial => "display", :collection => found_sales
Adam Crossland
Hrm, still doesnt work, sigh. Is there any possible way I can see the array within the view
You can always loop over the elements in the array in your view with each.
Adam Crossland
I'm only adding 4 values to a table, and that's it. The thing is, I have to be able to update the form after the user has edited the form
Cheers,works now