Skip to content

Instantly share code, notes, and snippets.

@chewmanfoo
Created March 9, 2011 21:26
Show Gist options
  • Select an option

  • Save chewmanfoo/863038 to your computer and use it in GitHub Desktop.

Select an option

Save chewmanfoo/863038 to your computer and use it in GitHub Desktop.
error using association.build
Models:
class VpnConfig < ActiveRecord::Base
...
has_many :vpn_accessible_local_nets, :dependent => :destroy
class VpnAccessibleLocalNet < ActiveRecord::Base
...
belongs_to :vpn_config
Controller:
class VpnConfigsController < ApplicationController
...
def new
@vpn_config = VpnConfig.new
...
1.times do
phase1 = @vpn_config.build_vpn_phase1_config
phase2 = @vpn_config.build_vpn_phase2_config
anet = @vpn_config.vpn_accessible_local_nets.build <--------------
end
Error:
NoMethodError (undefined method `build' for []:Array):
app/controllers/vpn_configs_controller.rb:32:in `new'
app/controllers/vpn_configs_controller.rb:29:in `times'
app/controllers/vpn_configs_controller.rb:29:in `new'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment