不知道是否即时推断这一点,但希望对此方案提供一些指导和建议。两个应用程序共享相同的数据库Rails
我有两个应用程序,一个可以登录并执行基本CRUD,即创建博客文章,第二个应用程序的视图,但无法登录,无法创建博客文章。第二个应用程序将从第一个应用程序的相同数据库读取。
我的问题是我如何从开发中的相同模型读取两个应用程序,我是否仍然需要创建我的模型与列等视图只应用程序?
例
应用1(带有CRUD)
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged
belongs_to :category
belongs_to :user
has_many :images, as: :imageable, :dependent => :destroy
accepts_nested_attributes_for :images
attr_accessible :comments, :title, :category_id, :user_id, :image_id, :images_attributes, :imageable_id, :imageable_attributes, :slug
#Validations
validates :comments, :presence => {:message => 'Add your Comments'}
validates :title, :presence => {:message => 'Add your Title'}
#scopes
scope :latest_posts, :order => "posts.created_at DESC"
#scope :ruby_posts, :include => :category, :conditions => {"categories.name" => "Ruby"}, :order => "posts.created_at DESC"
def self.search(search)
where("title like ?", "%#{search}%")
end
end
应用2(没有CRUD)
class Post < ActiveRecord::Base
#do i still provide all associations and attributes here?
end
我真的体会到了什么是这种事情的说明设置
谢谢
只是为了在我的脑海中澄清,在应用程序2中,我仍然会通过创建模型和设置关联和范围等的动作,就像您所说的那样。不要运行任何迁移,因为我们正在从应用程序中读取1.我如何在开发中共享数据库? – Richlewis
@Richlewis从概念上说,这听起来正确。尽管如此,我强烈建议将您的模型类移动到共享gem中,这样您不必再写两次。在开发中,您只需确保两个应用程序的'config/database.yml'指向相同的开发数据库。在App 1中通过迁移创建表格后,只要存在正确的模型类别,App 2就会看到它。 –
嗯共享宝石,没有做过之前:(尽管它的想法虽然作为保存创造一切两次 – Richlewis