Problem with passing to constructor

I think i’m doing something quite simple here but can;t quite get it: I
had a load of creation logic in my controller that i decided to move to
the model, under the ‘skinny controller’ principle. So, my controller
is now passing through the results from a form page, and another
argument of session[:user], to the model constructor:

#controller method
def create
if @article = Article.new params[:article], :user => session[:user]
flash[:notice] = ‘Article was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

#model constructor
def initialize(params = {})
super
if self.title == “”
self.title =
(Hpricot(open(@article.url))/“title”).first.inner_html
end
self.added_at = DateTime.now.to_s
self.user_id = params[:user]
self.points = 1
return self.save
end

But i’m getting an error that looks like a basic syntax error from the
controller:
app/controllers/article_controller.rb:23: syntax error, unexpected
tIDENTIFIER, expecting kTHEN or ‘:’ or ‘\n’ or ‘;’
if @article = Article.new params[:article], :user => session[:user]

Can anyone see what’s wrong with my controller constructor call?

thanks in advance
max

Max W. wrote:

if @article = Article.new params[:article], :user => session[:user]

Try this:

if @article = Article.new(params[:article], :user => session[:user])

Lutz

Lutz H. wrote:

Max W. wrote:

if @article = Article.new params[:article], :user => session[:user]

Try this:

if @article = Article.new(params[:article], :user => session[:user])

Lutz

i actually tried that already, no joy…

Try this:

if @article = Article.new(params[:article], :user => session[:user])

Actually i just tried this again and it worked this time (buh? sorry),
but now i’m having problems in the model getting stuff out of the
params: this line in initialize is having a problem:

self.user_id = params[:user]

getting a nil object error “while evaluating nil.[]” - it looks like
params has been lost or something by the time i get to this line…I
must be passing :user through badly somehow. Do you know why?