Two applications using the same Rails database

I'm not sure if I overdo it, but would like to receive some recommendations and recommendations for this scenario.

I have two applications that you can enter and execute your main CRUD, i.e. create blog entries, and the second is to view the same application, but you won’t be able to log in and not create a blog entry. The second application will be read from the same database as the first.

My question is how can I get two applications reading the same model in development, and I still need to create my models with columns, etc. in view-only application?

Example

Appendix 1 (with 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

Appendix 2 (No Crud)

class Post < ActiveRecord::Base
#do i still provide all associations and attributes here?
end

I would really appreciate an explanation of what is going on in this kind of setup.

thanks

+4
1

, . , Post 2 , .

, , . .

. , , , , . , db/schema App 2 , , rake db:*.

, , " " , (attr_accessible accepts_nested_attributes_for) - ActiveRecord . ActiveRecord::Base#save 2 .

+6

Source: https://habr.com/ru/post/1523290/


All Articles