My update.html.erb:
<% @uploads.each do |upload| %>
<p><%= upload.name %></p>
<p class="grey">
<%= best_in_place upload, :place, type: :select, collection: [ ["Home", "Home"],["Sauna", "Sauna"]]%>
</p>
<%end%>
controller:
def show
@uploads = Upload.all
end
def update
@uploads = Upload.all
@upload = Upload.find(params[:id])
respond_to do |format|
if @upload.update_attributes(params[:upload])
format.html { redirect_to @upload, notice: 'Upload was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @upload.errors, status: :unprocessable_entity }
end
end
end
The problem is that I get the error: undefined method
each' for nil:NilClass` , meaning that my controllers do not pass my object to the variable @uploads. Why do not the do that and how can I fix it? Thanks in advance.
ps. I could write at the top of my view something like this:
<% @uploads=Uploads.all%>
But that is not the best idea. Thanks in advance