我想渲染從ajax響應部分。渲染部分只是從ajax渲染字符串
//app/assets/javascript/pages/contact.js
$("#new_message").on("ajax:success", function(event, data, status, xhr) {
$("#new_message").prepend("<%=j(render 'layouts/error_messages', object: f.object) %>")
});
這是從消息控制器
class MessagesController < ApplicationController
def contact
@message = Message.new(params[:message])
respond_to do |format|
if @message.valid?
ContactMailer.contact_me(@message)
format.html { redirect_to contact_path, notice: 'Message was sent successfully.' }
format.js { render nothing: true }
else
format.html { redirect_to contact_path }
format.js { render nothing: true }
end
end
end
end
我猜這個問題來自於部分它不是送的,我會在要發送的數據在我format.js塊。
當AJAX事件被稱爲它附加字符串,而不是使其
編輯*移動代碼contact.js.haml仍然使得它作爲字符串返回
$("#new_message").prepend("j(render partial:'layouts/error_messages', object: f.object))")
嘗試重命名網絡le to'contact.js.erb'以確保ERB標籤將被正確解釋 – omnikron