我有一个使用 AJAX 发送的表单。该表单位于 FirstsController
中。我需要将表单发送到 SecondsController
。表格已发送并保存数据。然后我想通过文本更改形式,我尝试这样做:
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 文件吗?
最佳答案
这是正确的设置:
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
。
关于javascript - 如何在Rails 3中通过AJAX进行respond_to?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9042155/