Skip to content

Instantly share code, notes, and snippets.

@heridev
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heridev/5733b5ea01995142f57b to your computer and use it in GitHub Desktop.
Save heridev/5733b5ea01995142f57b to your computer and use it in GitHub Desktop.
Problema con la api routes
# si deseas utilizar el codigo que adjuntas que es el siguiente
class Api::ResponsesController < ApplicationController
respond_to :json
def index
json_response = {
models: "hola"
}
respond_with json_response
end
end
namespace :api do
resources :responses,format: :json
end
# la ruta a la cual tienes que acceder
# es la siguiente liga
http://localhost:3000/api/responses.json
# si por el contrario no quieres especificar la extension puedes utilizar
# format: 'json' o tambien puedes utilizar el siguiente codigo :
class Api::ResponsesController < ApplicationController
def index
json_response = {
models: "hola"
}
render json: json_response
end
end
namespace :api do
resources :responses,format: :json
end
## como te comento son tres opciones utilizando respond_with y
# especificar en tu ruta la extension .json o cambiar
# el format a format: 'json' o utilizar render json: sin el
# respond_with y el format: :json como simbolo
@rxco
Copy link

rxco commented Jul 5, 2014

me quedo perfectamente claro José Heriberto, muchas gracias por tomarte el tiempo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment