开发者

Problem with Rails 3.0.0 and Ruby 1.8.7? Sporadic 'wrong number of arguments' error

I'm using Rails 3.0.0.rc with Ruby 1.8.7 on Snow Leopard. I was using Builder to to restrict what's returned by render :xml for a User model object. It wasn't working as expected, so I commented out my format.xml block.

E.g., this was my users_controller.rb:

  def create
    # TODO: Limit the frequency at which this can be called.
    @user = User.new
    @user.first_name = params[:user][:first_name]
    @user.last_name = params[:user][:last_name]
    # etc...

    respond_to do |format|
      if @user.save
        format.html { redirect_to(@user, :notice => 'User was successfully created.') }
        format.xml  { render :xml => @user, :status => :created, :location => @user }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
      end
    end
  end

I changed the first format.xml and commented out the block:

format.xml # { render :xml => @user, :status => :created, :location => @user }

When I removed my comment and reintroduced the block, I get an error:

ArgumentError (wrong number of arguments (1 for 0)):

app/controllers/users_controller.rb:80:in create'

app/controllers/users_controller.rb:77:in create'

I reformatted the code so the render :xml call is on its own line, just to confirm that this is the source of the problem.

What's going on? There are three arguments involved (not 1) and since when does render take zero arguments? Why did the error 开发者_JAVA百科only appear after I reverted the code to its original state?


Turns out the error wasn't being reported properly. I had an error in my Users::to_xml method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜