zatz zatz
2013-Nov-18 16:03 UTC
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(<params for connecting to db>)
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:in `method_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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/d01ec95f4915d032f1c85570223a1bd6%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.
zatz zatz
2013-Nov-18 17:51 UTC
Re: wrong number of arguements (1 for 0) on ActiveRecord::Base#send
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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/aa31fbd5460f82077b4654c476ad9a12%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.