Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active December 25, 2015 15:19
Show Gist options
  • Save mrded/6997495 to your computer and use it in GitHub Desktop.
Save mrded/6997495 to your computer and use it in GitHub Desktop.
Rails: How to render different format.
class CodesController < ApplicationController
def index
@codes = Code.all
respond_to do |format|
format.html
format.json do
render json: @codes,
only: [:id, :name, :description]
end
end
end
end
Opcs::Application.routes.draw do
get "codes/index(.:format)"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment