Wrong number of arguements (1 for 0) on ActiveRecord::Base#send

So I’m not exactly using Rails, but just ActiveRecord. Though I felt
this would be more appropriate in the Rails forum than the general Ruby
forum.

I’m working on an app that interacts with databases, without having a
database of its own.

I have a class called Modeller, and a Modeller#retrieve_model(name)
method that takes a name, looks for a table matching that name, creates
a model that inherits from ActiveRecord::Base and returns it. It works
great.

So I can enter:

m = Modeller.new()
model = m.retrieve_model(‘page’)

And I get back a model called Page, connected to the database and ready
to go.

But a problem occurs when I try to call methods on it with
BasicObject#send.

I take a list of fields from a yaml file (user supplied) then attempt to
update the fields with BasicObject#send.

yaml file example -
content: some content
parent_id: 1
children_count: 0
etc.

So my code ends up like this:

model.send(‘content’, ‘some content’)

And it blows up with an error:

ArgumentError: wrong number of arguments (1 for 0)
/home/zatz/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1
/lib/active_record/attribute_methods/read.rb:58:in
__temp__37964756f59646' /home/zatz/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.1 /lib/active_record/attribute_methods.rb:150:inmethod_missing’

And I’m stumped. What’s going on?

A very big thank you ahead of time to whoever can help me figure this
out. I’m totally open to an alternative way of doing this too.

Alright, I had a big brain fart with this one. I was confusing the
syntax with define_method.

It doesn’t work because it’s calling model.content(‘some content’).

What I need is model.content = ‘some content’.

So the correct invocation would be model.send(‘content=’, ‘some
content’).

Sorry for that, total not-thinking on my part.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs