# Problem calling super constructor

**URL:** <https://www.ruby-forum.com/t/problem-calling-super-constructor/114061>\
**Category:** Rails\
**Created:** [September 7, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/problem-calling-super-constructor/114061 "2007-09-07T13:58:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 7, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/problem-calling-super-constructor/114061/1 "2007-09-07T13:58:20Z")

</div>

I had a lot of messy controller code that i’m in the process of tidying  
up (moving logic into the models for example). Now, this no longer  
works and i don’t understand the message “undefined method `article=’  
for #Article:0x4518714” - can anyone explain this to me please?

Here’s my stack trace, i’ll go through it step by step afterwards -

C:/code/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1857:in  
`method_missing' C:/code/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1672:in`send’  
C:/code/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1672:in  
`attributes=' C:/code/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in`each’  
C:/code/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1671:in  
`attributes=' C:/code/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1505:in`initialize\_without\_callbacks’  
C:/code/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/callbacks.rb:225:in  
`initialize' #{RAILS_ROOT}/app/models/article.rb:29:in`initialize’  
#{RAILS\_ROOT}/app/models/article.rb:48:in `new' #{RAILS_ROOT}/app/models/article.rb:48:in`add\_article’  
#{RAILS\_ROOT}/app/controllers/article\_controller.rb:35:in `add’

OK - we start off with a form for getting some details for the new  
object, an Article:

\<% form\_tag :controller =\> ‘article’, :action =\> ‘add’ do %\>

Url  
\<%= text\_field 'article', 'url' %\>

Title  
\<%= text\_field 'article', 'title' %\>

Tags  
\<%= text\_field 'article', 'tags' %\>

 \<%= submit\_tag "Submit" %\> \<% end %\>

The results from this get passed through in a hash called :article to my  
controller ‘add’ method, which passes the params through the the model’s  
add\_article method, along with the current user:

def add  
if Article.add\_article :article =\> params[:article], :user\_id =\>  
session[:user]  
flash[:notice] = “Added a new article.”  
else  
flash[:notice] = “This article exists already. It has been  
automatically scored up for you.”  
end  
redirect\_to :controller =\> ‘article’, :action =\> ‘list’  
end

In the model’s add\_article method, i see if an article with the same url  
is already in the DB, and if it isn’t i call the constructor, just  
passing through the same params, unchanged:

def Article.add\_article(params = {})  
#see if we’ve already got it - if not, make a new one, if we do,  
score it up  
article = Article.find(:first, :conditions =\> [“url = ?”,  
params[:article][:url]])  
if article == nil  
Article.new params  
return true  
else  
article.change\_score :user\_id =\> params[:user\_id], :points =\> 1  
return false  
end  
end

And this is the constructor, which takes the params, which include the  
:article hash and the :user\_id value. I call super before anything else  
to make sure i get an ActiveRecord object. (the hpricot code is just  
used to autogenerate a title from a url)

def initialize(params = {})  
super  
if self.title == “” && self.url != “”  
self.title = (Hpricot(open(self.url))/“title”).first.inner\_html  
end  
self.added\_at = DateTime.now.to\_s  
self.points = 0  
self.change\_score :user\_id =\> self.user\_id, :points =\> 1  
self.user\_id = params[:user\_id]  
end

Looking at the trace, it looks like the call to super is causing the  
problem (line 29 is the super call line) - but this is unchanged from  
how it was working before. Can anyone see my problem?

thanks!  
max
