I have two Ruby on Rails projects on my computer. For some reason, when I generate a scaffold in one project I get:
# POST /users
# POST /users.xml
def create
@user = User.new(params[:user])
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
and in the other:
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render json: @user, status: :created, location: @user }
else
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
The weird thing is that I am generating both in the same computer.
When I do ruby -v I get 1.9.2.
How can I configure the scaffold to generate one or the other? Right now I am interested in .xml, but maybe I’ll switch both to json someday. Anyways, I know I can do this manually, but it is a lot of work if you have several tables (or even with one table). How can I tell rails I want one format in particular by default?
Most likely you’re using different version of rails in the two applications.. Rails 3.0 scaffold generates the xml code and Rails 3.1 scaffold generates the json code.. Check your gem list for multiple version of rails installed..