Skip to content

Instantly share code, notes, and snippets.

@salami-art
Created January 30, 2019 10:16
Show Gist options
  • Save salami-art/c69d48a78406dff6159ac5566540badf to your computer and use it in GitHub Desktop.
Save salami-art/c69d48a78406dff6159ac5566540badf to your computer and use it in GitHub Desktop.
class Font < ApplicationRecord
has_many :styles_fonts
has_many :styles, through: :styles_fonts
end
class Style < ApplicationRecord
has_many :styles_fonts, -> { distinct }, dependent: :destroy
has_many :fonts, -> { distinct }, through: :styles_fonts
accepts_nested_attributes_for :fonts
end
class Admin::StylesController < Admin::BaseController
def delete_font
@style = Style.find(params[:id])
@style.fonts.delete params[:font_id] # ActiveRecord::ActiveRecordError (delete_all doesn't support distinct):
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment