0
Rails 3.2
我有一個表:創建一個Rails模型來管理表
subscriptions_locations
有兩列:
subscription_id
location_id
但目前沒有應用程序的一部分,我可以通過對其進行管理ActiveRecord,如果我創建一個模型subscriptions_location.rb:
class SubscriptionsLocation < ActiveRecord::Base
attr_accessible :subscription_id, :location_id
end
,隨時隨地我想添加或刪除,我可以這樣做:
SubscriptionsLocation.find_by_subscription_id("some_subscription_id").destroy
和
sub_location = SubscriptionsLocation.new(:subscription_id => "something", :location_id => "something")
sub_location.save!
我已經添加了遷移文件遷移 – EastsideDeveloper