如何使的respond_to通过AJAX在Rails 3的? [英] How to make a respond_to by AJAX in Rails 3?
本文介绍了如何使的respond_to通过AJAX在Rails 3的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格,我发送使用AJAX。形式是在 FirstsController
。我需要的形式发送到 SecondsController
。将表单发送和保存数据。然后,我想通过文本改变的形式,我尽量做到通过这样的方式:
I have a form, that I send with using AJAX. The form is in the FirstsController
. I need the form send to SecondsController
. The form is sent and data saved. Then I wanna change the form by a text, I try to do by this way:
def create
...saving...
respond_to do |format|
format.js {
render :update do |page|; page << "$('#id_element').html('hellllloooooo');" end
}
format.html {}
end
end
和我是个收到此错误:
ActionView::MissingTemplate (Missing template seconds/update, application/update with {:handlers=>[:erb, :builder, :coffee], :formats=>[:js, :html], :locale=>[:en, :en]}.):
我应该如何设置JS请求回 FirstsController
? +需要任何帮助的* .js文件?
How should I set the JS request back to the FirstsController
? + is needed any help *.js file?
推荐答案
这是设置做正确的:
def create
...saving...
respond_to do |format|
format.js {
render 'firsts/action_that_you_want'
}
format.html {}
end
end
而在 FirstsController
是需要创建的文件 action_that_you_want.js.erb
。
And in the FirstsController
is needed to have created the the file action_that_you_want.js.erb
.
这篇关于如何使的respond_to通过AJAX在Rails 3的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文