diff --git a/app/controllers/artist_commentaries_controller.rb b/app/controllers/artist_commentaries_controller.rb index 875a3a67c..5e2f58e65 100644 --- a/app/controllers/artist_commentaries_controller.rb +++ b/app/controllers/artist_commentaries_controller.rb @@ -26,7 +26,7 @@ class ArtistCommentariesController < ApplicationController end def create_or_update - post_id = params[:artist_commentary].delete(:post_id) + post_id = params[:artist_commentary].delete(:post_id) || params[:post_id] @artist_commentary = authorize ArtistCommentary.find_or_initialize_by(post_id: post_id) @artist_commentary.update(permitted_attributes(@artist_commentary)) respond_with(@artist_commentary) diff --git a/app/views/artist_commentaries/_form.html.erb b/app/views/artist_commentaries/_form.html.erb index 4e11f0d31..f5256d1c6 100644 --- a/app/views/artist_commentaries/_form.html.erb +++ b/app/views/artist_commentaries/_form.html.erb @@ -10,9 +10,7 @@ -<%= edit_form_for(artist_commentary, url: create_or_update_artist_commentaries_path(format: :js), remote: true, method: :put, html: { id: "edit-commentary" }) do |f| %> - <%= f.input :post_id, as: :hidden, input_html: { value: post.id } %> - +<%= edit_form_for(artist_commentary, url: create_or_update_post_artist_commentary_path(post_id: post.id, format: :js), remote: true, method: :put, html: { id: "edit-commentary" }) do |f| %> <%= f.input :original_title, as: :string, input_html: { value: artist_commentary.try(:original_title) } %> <%= f.input :original_description, input_html: { value: artist_commentary.try(:original_description) } %> diff --git a/test/functional/artist_commentaries_controller_test.rb b/test/functional/artist_commentaries_controller_test.rb index 2de603418..0ca8fc880 100644 --- a/test/functional/artist_commentaries_controller_test.rb +++ b/test/functional/artist_commentaries_controller_test.rb @@ -49,7 +49,7 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest params = { artist_commentary: { original_title: "foo", - post_id: FactoryBot.create(:post).id + post_id: create(:post).id }, format: "js" } @@ -74,6 +74,19 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_equal("foo", @commentary.reload.original_title) end + + should "work for /posts/:post_id/artist_commentary/create_or_update" do + params = { + post_id: create(:post).id, + artist_commentary: { original_title: "foo" }, + } + + assert_difference("ArtistCommentary.count", 1) do + put_auth create_or_update_post_artist_commentary_path(params), @user, xhr: true + end + + assert_response :success + end end context "revert action" do