我正在尝试在form_for上执行ajax请求。只是在发送消息时,但是现在javascript没有触发。
可能是文件位置,因为我正在使用部分文件吗?
/layouts/_message.haml
= form_for @message, :remote => true do |f|
= f.text_field :body
%button{name: "commit", type: "submit"}
send
消息控制器:
def create
@message = Message.new(message_params)
if @message.create
flash[:success] = 'Message sent!'
redirect_to root_url
else
flash[:error] = 'Message was not sent!'
redirect_to root_url
end
end
/messages/show.haml
.chat
- @convo.each do |convo|
= convo.body
= render "layouts/message"
/messages/create.js.erb
$(".chat").append("Test append");
答案 0 :(得分:0)
我解决了。原来我的应用程序发送我的布局文件。所以我只做渲染:布局 - >假
def create
@message = Message.new(message_params)
@message.save
respond_to do |format|
format.html {
flash[:success] = 'Message sent!'
redirect_to message_path(id: params[:message][:username])}
format.js {render :layout => false}
end
end