Initialize, instance variable....wrong number of arguments!

Dear RoR Community

My new RoR experience went really smooth for some time until I got stuck
with a seemingly easy problem and the more I have tried to read about it
(PickAxe, Agile WD, forum, etc.) the more confused I got!
What I have done so far as a newbie is to use the scaffold and then
build my own ideas around it. What I am trying to do now is
allow/disallow an action in the input form (in this case ‘save’)
depending on whether the ‘status’ == WIP or not. However with the code
below I keep getting error messages like ‘wrong number of arguments (0
for 1)’ or ‘Template is missing’.
My 2 questions are:

  1. Can anyone see what is wrong with my code?
  2. Can anyone please give me some info or point me into the direction of
    where I can find info about instance variables, initialization for
    newbies like me?

Thanks a lot,

Alex

class AdminController < ApplicationController

def wipinput
@job = Job.find(params[:id])
end

def initialize(status)
@status = status
end

def wipupdate
if params[:save] and @status == ‘WIP’
@job = Job.find(params[:id])
if @job.update_attributes(params[:job])
@job.update_attribute(:status,“WIP”)
flash[:notice] = ‘Job was successfully updated.’
redirect_to :action => ‘wip’
else
render :action => ‘wipinput’
end

Hello Alex,

2006/5/13, Alex Sörensen [email protected]:

  1. Can anyone see what is wrong with my code?

Yes, remove the definition of #initialize. That is overriding the
method with the same name in ApplicationController or above.

  1. Can anyone please give me some info or point me into the direction of
    where I can find info about instance variables, initialization for
    newbies like me?

Instance variables are initialized to nil when first referenced. If
you need another value, in Rails, you could use a before filter. You
have to remember that the controller instance will be recreated for
each new request.

This is the equivalent of calling AdminController.new.wipupdate for
each request. Please bear in mind that this is not exactly how it
works, but it is similar in concept.

For your specific problem, you should look instead of storing your
status in the user’s session, not in the controller itself.

Hope that helps !

Salut Francois, hello ror

Thanks for the amazingly quick response!

After deleting #initialize, the following if statement produces
‘Template missing…wipupdate.rhtml’ even though is_status equals ‘WIP’
and should therefore just return the usual response, i.e. redirect_to
:action => ‘wip’ which works fine if I leave out the second part of the
if statement (and @is_status == ‘WIP’). Any idea?

Thanks a lot, Alex

def wipupdate
if params[:save] and @is_status == ‘WIP’

François Beausoleil wrote:

Hello Alex,

2006/5/13, Alex Sörensen [email protected]:

  1. Can anyone see what is wrong with my code?

Yes, remove the definition of #initialize. That is overriding the
method with the same name in ApplicationController or above.

  1. Can anyone please give me some info or point me into the direction of
    where I can find info about instance variables, initialization for
    newbies like me?

Instance variables are initialized to nil when first referenced. If
you need another value, in Rails, you could use a before filter. You
have to remember that the controller instance will be recreated for
each new request.

This is the equivalent of calling AdminController.new.wipupdate for
each request. Please bear in mind that this is not exactly how it
works, but it is similar in concept.

For your specific problem, you should look instead of storing your
status in the user’s session, not in the controller itself.

Hope that helps !