FrontEnd에서 연결을 구현하려고했지만 현재 웹 사이트에 직접 연결된 데이터베이스가 없으므로 ActiveRecord를 사용할 수없고 ActiveModel 만 사용할 수 있습니다. 모델의 검증 및 핵심 기능을 지원합니다. 이제 개체와 함께 보낼 중첩 된 특성, 즉 사용자와 연결된 주소를 사용해야하므로이 모델에서는 먼저 해당 모델에서 연결을 정의해야합니다. 그러나 연관을 정의한 후에는 사용자 모델에 정의되지 않은 "has_many"메서드 예외가 발생합니다. 현재 웹 사이트에서 구현하고 중첩 된 속성의 로직을 구현하는 방법을 찾고 있습니다. 당신이 나에게 이와 관련된 것을 제안 할 수 있거나 과거에 그러한 문제를 만난 적이 있다면 정말 좋을 것입니다.
나는 또한 https://github.com/softace/activerecord-tableless 보석을 사용하는 접근 방식을 시도했지만 나를 위해 작동하지 않습니다. 또한 나는 tableless.rb테이블이없는 모델에 대한 연결
tableless.rb
class Tableless < ActiveRecord::Base
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
def self.columns()
@columns ||= [];
end
def self.columns_hash
h = {}
for c in self.columns
h[c.name] = c
end
return h
end
def self.column_defaults
Hash[self.columns.map{ |col|
[col.name, col.default]
}]
end
def self.descends_from_active_record?
return true
end
def persisted?
return false
end
# override the save method to prevent exceptions
end
그러나 다음과 같은 예외 예외 받고 추가했습니다 :
콘솔 오류 :
ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:203:in `table_exists?'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/primary_key.rb:92:in `get_primary_key'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/primary_key.rb:77:in `reset_primary_key'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/primary_key.rb:65:in `primary_key'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/primary_key.rb:79:in `reset_primary_key'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/primary_key.rb:65:in `primary_key'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/write.rb:32:in `write_attribute'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/dirty.rb:70:in `write_attribute'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/write.rb:19:in `__temp__9646='
from /home/cis/API_OTGJ/Tableless/app/models/book.rb:13:in `block in initialize'
from /home/cis/API_OTGJ/Tableless/app/models/book.rb:12:in `each'
from /home/cis/API_OTGJ/Tableless/app/models/book.rb:12:in `initialize'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in `new'
from /home/cis/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in `new'
from (irb):19
from /home/cis/.rvm/gems/[email protected]/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /home/cis/.rvm/gems/[email protected]/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /home/cis/.rvm/gems/[email protected]/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
https://github.com/softace/activerecord-tableless를 사용할 때의 문제점은 무엇입니까? – marvelousNinja