Sunday, 18 August 2013

undefined method `[]=' for nil:NilClass

undefined method `[]=' for nil:NilClass

I keep getting this undefined error when I try to submit this form with
nested attributes, not sure where it's coming from been wrestling with it
for quite a while now, I am trying to let users select an option in the
council model the submit their choice, I am not sure if I have my
associations wired up correctly or if the error is coming from the form.
Am a noob to rails. Thanks in advance.
Error
Started PUT "/properties/5/build/council" for 127.0.0.1 at 2013-08-18
08:52:07 +0100
Processing by Properties::BuildController#update as HTML
Parameters:
{"utf8"=>"✓","authenticity_token"=>"wBWQaxtBioqzGLkhUrstqS+cFD/xvEutXnJ0jWNtSa0=",
"council_id"=>"1", "commit"=>"Save changes", "property_id"=>"5",
"id"=>"council"}
Property Load (0.2ms) SELECT "properties".* FROM "properties" WHERE
"properties"."id" = ? LIMIT 1 [["id", "5"]]
Completed 500 Internal Server Error in 35ms
NoMethodError - undefined method `[]=' for nil:NilClass:
Council View
<h1>Select Council</h1>
<%= form_tag url_for(:action => 'update', :controller =>
'properties/build'), :method => 'put' do %>
<%= select_tag :council_id,
options_from_collection_for_select(Council.all, :id, :name) %>
<%= submit_tag %>
<% end %>
Controller
class Properties::BuildController < ApplicationController
include Wicked::Wizard
steps :tenant, :meter, :council, :confirmed
def show
@property = Property.find(params[:property_id])
@tenants = @property.tenants.new(params[:tenant_id])
@meter = @property.build_meter
@council = @property.build_council
render_wizard
end
def edit
@property = Property.find(params[:property_id])
end
def update
@property = Property.find(params[:property_id])
params[:property][:status] = step.to_s
params[:property][:status] = 'active' if step == steps.last
@property.update_attributes(params[:property])
render_wizard @property
end
end
Council.rb
class Council < ActiveRecord::Base
attr_accessible :CouncilEmail, :name, :CouncilTel
belongs_to :property
end
Propery.rb
class Property < ActiveRecord::Base
attr_accessible :name, :address_attributes, :tenants_attributes,
:meter_attributes, :council_attributes, :property_id, :status
belongs_to :user
has_one :address, :as => :addressable
accepts_nested_attributes_for :address, :allow_destroy => true
has_one :council
accepts_nested_attributes_for :council, :allow_destroy => true

No comments:

Post a Comment