So I have the class 'Range' created by Datamapper (this is in a Ruby/Sinatra project):
class Range
include DataMapper::Resource
#properties
property :id, Serial, :key => true
property :default_gateway, String
property :subnetmask, String
property :main_ip, String
property :backup_ip, String
property :dhcp, String
#relations
belongs_to :vlan, :required => true
has n, :dhcp
end #class Range
I also have a file 'initdata' which I call in my main class. A part of this file tries to fill up the database with some dummy data. The problem is with the class Ranges it gives me an ArgumentError.
Initdata ruby file:
#CREATE RANGES
if Range.count == 0
puts '----- ADDING RANGES -----'
range1 = Range.first_or_create(:default_gateway => '10.1.2.44', :subnetmask => '0.0.255.255', :main_ip => '10.1.0.1', :backup_ip => '10.1.0.2', :dhcp => '192.168.1.2', :vlan_id => 1)
range1.errors.each do |error|
puts error
end
end
I get the following error when I run it in the terminal:
----- ADDING RANGES -----
/home/bene/.rvm/gems/ruby-2.1.3/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `initialize': wrong number of arguments (1 for 2..3) (ArgumentError)
from /home/bene/.rvm/gems/ruby-2.1.3/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `new'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `create'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/dm-core-1.2.0/lib/dm-core/model.rb:444:in `first_or_create'
from /home/bene/project/development_sam/lan_portal/dal/initdata.rb:328:in `<top (required)>'
from /home/bene/project/development_sam/lan_portal/app.rb:6:in `require'
from /home/bene/project/development_sam/lan_portal/app.rb:6:in `<top (required)>'
from /home/bene/project/development_sam/lan_portal/config.ru:1:in `require'
from /home/bene/project/development_sam/lan_portal/config.ru:1:in `block in <main>'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /home/bene/project/development_sam/lan_portal/config.ru:in `new'
from /home/bene/project/development_sam/lan_portal/config.ru:in `<main>'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:250:in `start'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:141:in `start'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/bin/rackup:4:in `<top (required)>'
from /home/bene/.rvm/gems/ruby-2.1.3/bin/rackup:23:in `load'
from /home/bene/.rvm/gems/ruby-2.1.3/bin/rackup:23:in `<main>'
from /home/bene/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'
from /home/bene/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'
Does anyone have any idea what I might be doing wrong? I've searched for it, but most solutions are because people wrote their own 'initialize' function, as in my case, it's already defined by DataMapper
There is a core Ruby class Range (which, incidentally, has a 2..3-argument constructor); Appearently, DataMapper does not redefine a constructor if one already exists.
You need to rename your class.