rails-models

Shared models between two Rails apps - what is the ideal solution for Workflow?

这一生的挚爱 提交于 2019-11-28 16:29:37
I am currently working on a Rails 3 project that is divided up into four parts: The public facing website The administration website/backend The models The API for third party data access As the models are shared between the three key components I want to keep them away from being in one main project, however each part needs access to the models, but I don't want to repeat the code and have different versions everywhere. Currently I have the model code in a gem, and in each project's Gemfile I am referencing them with the following line: gem "my_models", :path => "../my_models/" However when I

What is the best way to drop a table & remove a model in Rails 3?

风格不统一 提交于 2019-11-28 16:10:59
I have a model & a table which I no longer need in my App, I could leave them there but I would like to remove them to keep things tidy. I'm trying to figure out the best way to remove them with out messing around with my migrations & db/schema.rb files & any side effect it could have on my production environment, my app is on Heroku. I'm using PostgreSQL on both my local machine & heroku. So far I've found two ways to do this but am not sure which is the best method/ rails way? Method 1 I thought about just going in to my database & dropping the table & then destroying the model. rails db

How to have multiple conditions in a named scope?

主宰稳场 提交于 2019-11-28 00:51:07
问题 I have a User model. I can check whether a User is an admin by doing a_user.try(:admin?) . I'd like to define a named scope that gets all Users updated within the last X minutes who are not admins. So far I have: scope :recent, lambda { { :conditions => ['updated_at > ?', 5.minutes.ago] } } This successfully gets all Users updated within the last 5 minutes, but how do I incorporate the admin check? I don't know how to call try() on an instance of a User inside the scope... 回答1: if admin

What is the best way to drop a table & remove a model in Rails 3?

江枫思渺然 提交于 2019-11-27 19:54:17
问题 I have a model & a table which I no longer need in my App, I could leave them there but I would like to remove them to keep things tidy. I'm trying to figure out the best way to remove them with out messing around with my migrations & db/schema.rb files & any side effect it could have on my production environment, my app is on Heroku. I'm using PostgreSQL on both my local machine & heroku. So far I've found two ways to do this but am not sure which is the best method/ rails way? Method 1 I

Rails has_one :through association

℡╲_俬逩灬. 提交于 2019-11-27 10:04:44
问题 Rails has a has_one :through association that helps set up a one-to-one association with a third model by going through a second model. What is the real use of that besides making a shortcut association, that would otherwise be an extra step away. Taking this example from the Rails guide: class Supplier < ActiveRecord::Base has_one :account has_one :account_history, :through => :account end class Account < ActiveRecord::Base belongs_to :supplier has_one :account_history end class