https://github.com/dockyard/postgres_ext-serializerspostgres_ext/serializers मदद ... इतना आसान लगता है, लेकिन के रूप में वर्णित
यह इतना सेटअप करने के लिए सरल लगता है काम करने के लिए कुछ भी नहीं मिल सकता है, लेकिन मैं में काम करने के लिए किसी भी बुनियादी कार्यक्षमता प्राप्त नहीं कर पा रहे जेएसओएन को रेल से पोस्टग्रेस तक ले जाने की शर्तें। मैंने अपने एएसएस इनिट में, मेरे विशिष्ट धारावाहिकों और मेरे मॉडल में निम्नलिखित शामिल करने का प्रयास किया, लेकिन ऐसा लगता है कि यह सक्रिय नहीं होता है।
मैं ऑन रेल्स 4.2.3 और रूबी 2.2
हूँ और यह मैं क्या एक से अधिक फ़ाइलों को जोड़ने की कोशिश की है है:
की आवश्यकता होती है 'postgres_ext/serializers'
वास्तव में आपकी मदद की सराहना करते हैं, मुझे पता है कि मुझे कुछ स्पष्ट याद आना चाहिए।
अद्यतन: थोड़ा अधिक संदर्भ प्रदान करने के लिए, यह आप इस मणि के लिए README.md निर्देश पढ़ें, यह सिर्फ कहते हैं, "
बस 'postgres_ext/serializers' की आवश्यकता होती है और ActiveModel का उपयोग :: ! serializers के रूप में आप सामान्य रूप से
तो मैं अपने application.rb करने के लिए 'postgres_ext/serializers' की आवश्यकता होती है जोड़ा जाएगा, देखने के लिए एक serializer लिए एक छोटा सा संपादन किया है अगर यह काम किया:
class UserSerializer < ActiveModel::Serializer
cached false
attributes :id, :username, :location, :full_name
def full_name
"#{object.first_name} #{object.last_name}"
end
def full_name__sql
"first_name || ' ' || email"
end
end
तो मैं चल पाएंगे मेरी रेल कंसोल में निम्नलिखित:
users = User.first(10)
ActiveModel::ArraySerializer.new(users, each_serializer: UserSerializer).to_json
लेकिन __sql पूरा नाम विशेषता कभी नहीं दिखाया गया था और यह किसी भी पहले की तुलना में अलग तरह से postgres से डेटा खींच करने के लिए नहीं मालूम था।
और यही मेरी application.rb लग रहा है जैसे:
# require 'postgres_ext/serializers' ### Doesn't work here
require File.expand_path('../boot', __FILE__)
require 'rails/all'
require 'postgres_ext/serializers'
Bundler.require(*Rails.groups)
module Baller
class Application < Rails::Application
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
# From: http://www.benfranklinlabs.com/where-to-put-rails-modules/
# config.autoload_paths += %W(#{config.root}/lib) # add this line
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
end
end
धन्यवाद!
कृपया अपने प्रश्न में सटीक त्रुटि संदेश जोड़ें। वास्तव में क्या काम नहीं करता है और आप उसे कैसे जानते हैं? – EugZol
@EugZol ने अभी मेरी पोस्ट में अधिक जानकारी दी है। तलाश के लिए धन्यवाद! – Hawk