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

@@ -1,15 +1,13 @@
<%= edit_form_for(@artist) do |f| %>
<% if @artist.new_record? %>
<%= f.input :name, as: :string, input_html: { data: { autocomplete: "tag" } } %>
<% else %>
<%= f.input :name, as: :string, input_html: { data: { autocomplete: "tag" } }, hint: "Change to rename this artist entry and its wiki page" %>
<% end %>
<%= f.input :name, as: :string, input_html: { "data-autocomplete": "tag" } %>
<%= f.input :other_names_string, label: "Other names", as: :text, input_html: { size: "50x1" }, hint: '<b style="color: red;">NEW</b> Separate names with spaces, not commas. Use underscores for spaces inside names.'.html_safe %>
<%= f.input :group_name %>
<%= f.input :url_string, :label => "URLs", :as => :text, :input_html => {:size => "50x5", :value => params.dig(:artist, :url_string) || @artist.urls.join("\n")}, :hint => "You can prefix a URL with - to mark it as dead." %>
<%= f.input :url_string, :label => "URLs", :as => :text, :input_html => {:size => "50x15", :value => params.dig(:artist, :url_string) || @artist.urls.join("\n")}, :hint => "You can prefix a URL with - to mark it as dead." %>
<%= f.simple_fields_for :wiki_page do |fw| %>
<%= fw.input :body, label: "Wiki", input_html: { size: "50x15" } %>
<% end %>
<%= dtext_field "artist", "notes" %>
<%= f.button :submit, "Submit" %>
<%= dtext_preview_button "artist", "notes" %>
<% end %>

View File

@@ -5,9 +5,9 @@
<div id="a-show">
<h1>Artist: <%= link_to @artist.pretty_name, posts_path(tags: @artist.name), class: tag_class(@artist.tag) %></h1>
<% if @artist.notes.present? %>
<% if @artist.wiki_page.present? %>
<div class="prose">
<%= format_text(@artist.notes, :disable_mentions => true) %>
<%= format_text(@artist.wiki_page.body, :disable_mentions => true) %>
</div>
<p><%= link_to "View wiki page", @artist.wiki_page %></p>