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:increate'
create'
app/controllers/users_controller.rb:77:in
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 only appear after I reverted the code to its original state?