Hi everyone,
I have a partial containing a few input elements to edit the properties
of a
vehicle. Those input fields are of course within a form, but they are
not
the only ones in there. Now when my page loads, I want to display all
vehicles already added by the current user. So I thought I’d prepare a
collection of appropriate vehicles in @vehicles and let the view render
the
vehicles using
<% if @vehicles %>
<%= render :partial => "vehicle", :collection => @vehicles %>
<% end %>
The thing is, as I need to display more than one vehicle “form”, I need
to
give each input field a reference to the id of the underlying
activercord.
I’m trying this using
<%= text_field ‘vehicle[]’, ‘acquisition_cost’, { :class =>
“autosave_object”, :“tmt:required” => “true”, :“tmt:filters” =>
“numbersonly”, :size => 5, :tabindex => 4 } %>
As said in AWDWR the [] after the instance variable name adds the id to
the
name attribute of the textfield. Unfortunately, there is no instance
variable called @vehicle in my controller since I only have the
collection
@vehicles. I get the following error
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.id_before_type_cast
Of course there is a local variable called vehicle. I can use it to
manually
build the necessary name attribute for the html input field. However,
the
input field is NOT connected to any instance variable, since there
simply is
none to connect to
Any ideas how to approach this?
cheers
Martin Gamsjäger