Chris P.
2014-Jun-12 14:18 UTC
ActiveModel Serailizers, how can I load it and why do I need to?
Noobie here. The gist of my problem is this. If I move from serializer file from app/serializers/ to app/models/ then everything works fine. My JSON API will output my data according to my serializer. However, if I remove the copy from the app/models/ directory... it no longer works and goes back to Rails default JSON output. What do I need to do to include my serializer file in app/serializers/? **/app/serializers/item_serializer.rb** class ItemSerializer < ActiveModel::Serializer attributes :id, :name end **/app/controllers/items_controller.rb** class ItemsController < ApplicationController respond_to :json def index items = Item.all respond_with ({ success: :true, items: items }.as_json) end def show @item = Item.find_by_id(params[:id]) if @item render json: @item, serializer: ItemSerializer else render json: { success: :false, error: "Could not find item."}, status: :not_found end end end Do I HAVE TO have my serializers in /app/models by default. Why would ActiveModel Serializers default generating a new serializer then to the /app/serializers directory. How do I let my controller know about my serializer? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8c967aaa4a19f33f3856221348bff1ff%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.