User.rb
has_one :subscription, :inverse_of => :user
Subscription.rb
has_one :credit_card, :inverse_of => :subscription
CreditCard.rb
belongs_to :user, :inverse_of => :credit_card
belongs_to :subscription, :inverse_of => :credit_card
In credit card controller:
def new
@credit_card = current_user.build_credit_card
end
def create
@credit_card = current_user.build_credit_card
end
if @credit_card.save
if @credit_card.save
format.html { redirect_to @credit_card, notice: 'Credit card was successfully created.' }
format.json { render action: 'show', status: :created, location: @credit_card }
else
format.html { render action: 'new' }
format.json { render json: @credit_card.errors, status: :unprocessable_entity }
end
end
However, I'm still able to add multiple credit cards to my user model. How can this be possible? Only a has_many should emit such behaviour if I'm correct? A has_one association should prevent additional entities from being created, apart from one as far as I know..
I tried all variations, but still no luck.
Any help would be much appreciated!
Thank you.