artists/edit: refactor editing nested wiki pages.

Refactor to use accepts_nested_attributes_for instead of the notes
attribute to facilitate editing wikis on the artist edit page.

This fixes the notes attribute unintentionally showing up in the API.

This also changes it so that renaming an artist entry doesn't
automatically rename the corresponding wiki page. This had bad behavior
when there was a conflict between wiki pages (the wikis would be
silently merged, which usually isn't what you want). It also didn't warn
about wiki links being broken by renames.
This commit is contained in:
evazion
2020-02-16 18:27:57 -06:00
parent 6f3d0b542c
commit ef3188a7fe
6 changed files with 22 additions and 119 deletions

View File

@@ -6,10 +6,12 @@ class ArtistsController < ApplicationController
def new
@artist = Artist.new_with_defaults(artist_params(:new))
@artist.build_wiki_page if @artist.wiki_page.nil?
respond_with(@artist)
end
def edit
@artist.build_wiki_page if @artist.wiki_page.nil?
respond_with(@artist)
end
@@ -93,6 +95,7 @@ class ArtistsController < ApplicationController
def artist_params(context = nil)
permitted_params = %i[name other_names other_names_string group_name url_string notes is_active]
permitted_params << { wiki_page_attributes: %i[id body] }
permitted_params << :source if context == :new
params.fetch(:artist, {}).permit(permitted_params)