简体   繁体   English

Ruby on Rails form_remote_tag缺少模板

[英]Ruby on Rails form_remote_tag missing template

I'm using form_remote_tag(:url => {:controller => "home", :action => "search"}, :update => "mydiv") . 我正在使用form_remote_tag(:url => {:controller => "home", :action => "search"}, :update => "mydiv") When I click submit on the form "mydiv" is populated with the error "Template is missing. Missing template home/search.erb in view path app/views". 当我单击“ mydiv”表单上的“提交”时,出现错误“模板丢失。视图路径app / views中缺少模板home / search.erb”。 I've tried multiple render options in def search , but they all result in the same error. 我在def search尝试了多个render选项,但是它们都导致相同的错误。

It looks like the search method is trying to use it's default render even though I'm specifying what I want. 即使我指定了所需的内容,搜索方法似乎仍在尝试使用其默认渲染。

I've tried: 我试过了:
render 'index'
render :text => 'Return this from my method!'

Is my url incorrect? 我的网址不正确吗? Is it not submitting back to my home controller's search method? 是否不提交回我的家庭管理员的搜索方法?

Try 尝试

render :action => 'index'

this will use "index.rhtml" or "index.html.erb". 这将使用“ index.rhtml”或“ index.html.erb”。

I will try to explain why it said search.erb is not found, lets take create action for a some model, if there is some error in my create action they it will throw missing template create.html.erb file, since you have some error in your create action rails will try to render the create.html.erb in the page. 我将尝试解释为什么未找到search.erb的原因,让我们为某些模型执行create动作,如果我的create动作中存在一些错误,它们会抛出缺少的模板create.html.erb文件,因为您有您的create action rails中的错误将尝试在页面中呈现create.html.erb。 Hope I explained it clearly. 希望我能解释清楚。

In an ajax action you can't use redirect_to or render options directly. 在ajax操作中,您不能直接使用redirect_to或渲染选项。 try using this in your search action 尝试在搜索操作中使用它

render :update do |page|
  page.replace_html "ur_div_id","partial"
end

The form_remote_tag needs prototype to function. form_remote_tag需要原型才能运行。 Make sure you are including the :defaults for your javascript libraries namely prototype. 确保您的JavaScript库包括:defaults ,即原型。

<%= javascript_include_tag :defaults %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM