为什么我没有在刷新页面的网页上看到我的Ajax更新?

时间:2017-10-28 15:09:49

标签: javascript ruby-on-rails ajax

为什么我的网页没有通过Ajax自行更新,即使我在 ruby​​ on rails 中使用form_with?我错过了什么?如果您需要发布更多信息以获取帮助,请告诉我们。

堆栈跟踪

 Started GET "/artists/1" for 127.0.0.1 at 2017-10-28 15:45:54 +0200
 Processing by ArtistsController#show as JS
  Parameters: {"id"=>"1"}
  Artist Load (0.2ms)  SELECT  "artists".* FROM "artists" WHERE 
 "artists"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendering artists/show.html.erb within layouts/application
  Photo Load (0.2ms)  SELECT "photos".* FROM "photos" WHERE 
 "photos"."artist_id" = $1  [["artist_id", 1]]
  Song Load (0.2ms)  SELECT "songs".* FROM "songs" WHERE 
 "songs"."artist_id" = $1  [["artist_id", 1]]
  Rendered collection of songs/_song.html.erb [4 times] (3.6ms)
  Rendered songs/_form.html.erb (3.3ms)
  Rendered artists/show.html.erb within layouts/application (60.5ms)
Completed 200 OK in 154ms (Views: 133.6ms | ActiveRecord: 0.7ms)

代码

songscontroller:
class SongsController < ApplicationController
  def create
    @artist = Artist.find(params[:artist_id])
    @song = @artist.songs.create(song_params)
    redirect_to artist_path(@artist)
  end
end

<%= form_with(model: [ @artist, @artist.songs.build ]) do |form| %>
  <p>

    <%= form.text_field :name %>
  </p>
  <p>
    <%= form.submit %>
  </p>
<% end %>

1 个答案:

答案 0 :(得分:0)

你的争论没有刷新,因为get方法在你的show动作中作为JS处理,它应该是html或*/*