1
У меня есть эти файлы, и я могу получить, что работает ActiveModel Serializer.Rails 4.2 + ActiveModel Serializer 0.8.3
#
# congif/routes.rb
namespace :dealer do
resources :users do
resources :orders do
get 'search_dealer_profile', on: :collection
#
# app/serializers/profile_serializer.rb
class ProfileSerializer < ActiveModel::Serializer
attributes :id
end
#
# app/controllers/dealer/orders_controller.rb
class Dealer::OrdersController < Dealer::BaseController
def search_dealer_profile
profile = Profile.where(id: params[:id]).first
# I tried
#
# => Return a Json without use AMS. Object {id: 4, user_id: 4, name: "Alex", surname: "Sensation"…}
render json: profile
# => Works in console but here I get this : uninitialized constant Dealer::OrdersController::ProfileSerializer
render json: ProfileSerializer.new(profile).as_json
end
json
, что я хочу
{:profile=>{:id=>4}}
Я использую
- Rails 4.2.0
- active_model_serializer 0.8.3
Кто-нибудь может мне помочь?
и в каком формате вы получите его теперь? –
Если я использую ** render json: profile **, он возвращает полный профиль json object: {id: 4, user_id: 4, name: "Alex" ... + все атрибуты профиля – edudepetris