This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/controllers/api/api_controller.rb | |
class Api::ApplicationController < ActionController::Metal | |
include ActionController::Rendering | |
respond_to :json | |
end | |
#app/controllers/api/v1/tasks_controller.rb | |
module Api | |
module V1 | |
class TasksController < Api::ApplicationController | |
def do_something | |
render :json => Task.find(params[:id]).to_json | |
end | |
end | |
end | |
end | |
#routes | |
namespace :api , defaults: {format: 'json'} do | |
namespace :v1 do | |
resources :tasks, :only => [] do | |
member do | |
get 'do_something' | |
end | |
end | |
end | |
end | |
I was trying to figure out how to code an API using ActionController::Metal and yours was the first page out of dozens I tried with something that actually works. Thanks!
ReplyDeletethank u
ReplyDelete