In a controller method I am doing this:
destination = Destination.new(params[:destination])
trip = Trip.find(params[:trip_id])
destination.city_id = params[:city_id]
destination.trip_id = params[:trip_id]
last_destrination = Destination.find(:last, :order => 'sort', :conditions => { :trip_id => params[:trip_id] })
destination.sort = last_destrination ? last_destrination.sort.to_i + 1 : 1
if trip.user_id == current_user.id and destination.save
city = City.find(params[:city_id])
render :json => [ 'destination' => destination, 'city' => city ]
else
render :status => 500
end
Now I want to send the destination I just make along with the city associated with it. How the heck can I do that, as right now I get the following :
[
{
city: {
city: {
# name: "Fort Frances"
# latitude: 48.617
# created_at: "2010-12-23T16:04:00Z"
# updated_at: "2010-12-23T16:04:00Z"
# country_id: 43
# timezone: "-05:00"
# id: 951
# region_id: 34
# longitude: -93.417
}
},
destination: {
destination: {
# trip_id: 10
# created_at: "2010-12-23T21:24:27Z"
# updated_at: "2010-12-23T21:24:27Z"
# id: 29
# sort: 18
# city_id: 951
}
}
}
]
That all works fine except for the doubling up of array key names. destination.destination is no good. Any ideas?
–edit
This should render a single object with destination and city keys:
That setting would probably be better in a separate initializer if its used throughout the application.