模板与一个Ajax请求缺少错误 - 的Rails 3.1 [英] Template Missing error with an Ajax request - Rails 3.1
本文介绍了模板与一个Ajax请求缺少错误 - 的Rails 3.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Rails 3.1的应用程序使用Ruby 1.8.7。我试图创建通过AJAX的联系,但要得到一个缺少模板错误。
而ActionView :: MissingTemplate(缺少模板接触/创建,应用程序/创建{:处理器=> [:咖啡:建设者,:ERB]:区域=> :恩,:EN]:格式=> [:HTML]}搜查:
*/用户/ ME /网站/ T3 /应用程序/视图
):
形式:
<%=的form_for @contact,:远程=>真做| F | %>
<%= f.hidden_field:CUSTOMER_ID,:价值=> @ customer.id%>
<表>
&其中; TR>
< TD类=PTEN>
<%= f.text_field:FIRST_NAME,:风格=> 宽度:120px;,:类=> contact_input%>
< / TD>
< TD类=PTEN>
<%= f.text_field:姓氏,:风格=> 宽度:120px;,:类=> contact_input%>
< / TD>
< TD类=PTEN>
<%= f.text_field:位置,:风格=> 宽度:120px;,:类=> contact_input%>
< / TD>
< TD类=PTEN>
<%= f.text_field:电话:风格=> 宽度:120px;,:类=> contact_input%>
< / TD>
< TD类=PTEN>
<%= f.text_field:EXT,:风格=> 宽度:60PX;,:类=> contact_input%>
< / TD>
< TD类=PTEN>
<%= f.text_field:电子邮件:风格=> 宽度:200像素;,:类=> contact_input%>
< / TD>
< TD类=PTEN>
<%= f.submit创建,:类=> 提交%>
< / TD>
< / TR>
< /表>
<%结束%GT;
控制器:
高清创建
@contact = Contact.new(PARAMS [:联系人])
@customer = @ contact.customer
@ contact.save
respond_to代码做|格式|
format.js
结束
结束
Create.js.erb:
$(。CONTACT_LIST)追加(<%= escape_javascript(渲染@contact)%>中);
$('。contact_input:输入)VAL('')。
Development.rb:
MYAPP :: Application.configure做
这里指定#设置将precedence要比在配置/ application.rb中
#在开发环境中应用程序的code被重新加载
#每个请求。这大大降低了响应时间,但非常适合发展
#因为你没有当你code的变化重新启动Web服务器。
config.cache_classes = FALSE
#登录错误消息,当您不小心对nil调用方法。
config.whiny_nils =真
#显示完整的错误报告和禁用缓存
config.consider_all_requests_local =真
config.action_controller.perform_caching = FALSE
#不在乎的邮件无法发送
config.action_mailer.raise_delivery_errors = FALSE
#打印德precation通知到Rails的记录器
config.active_support.de precation =:日志
#只能使用最标准的支持,内置的浏览器
config.action_dispatch.best_standards_support =:内置
#不要COM preSS资产
config.assets.com preSS = FALSE
#扩展其装入资产线
config.assets.debug =真
结束
解决方案
我想你已经把它命名为Create.js.erb而不是create.js.erb了。
I have a rails 3.1 app with Ruby 1.8.7. I'm trying to create contacts via ajax, but keep getting a missing template error.
ActionView::MissingTemplate (Missing template contacts/create, application/create with {:handlers=>[:coffee, :builder, :erb], :locale=>[:en, :en], :formats=>[:html]}. Searched in:
* "/Users/Me/Sites/t3/app/views"
):
The form:
<%= form_for @contact, :remote => true do |f| %>
<%= f.hidden_field :customer_id, :value => @customer.id %>
<table>
<tr>
<td class="pten">
<%= f.text_field :first_name, :style => "width:120px;", :class => "contact_input" %>
</td>
<td class="pten">
<%= f.text_field :last_name, :style => "width:120px;", :class => "contact_input" %>
</td>
<td class="pten">
<%= f.text_field :position, :style => "width:120px;", :class => "contact_input" %>
</td>
<td class="pten">
<%= f.text_field :phone, :style => "width:120px;", :class => "contact_input" %>
</td>
<td class="pten">
<%= f.text_field :ext, :style => "width:60px;", :class => "contact_input" %>
</td>
<td class="pten">
<%= f.text_field :email, :style => "width:200px;", :class => "contact_input" %>
</td>
<td class="pten">
<%= f.submit 'Create', :class => "submit" %>
</td>
</tr>
</table>
<% end %>
The controller:
def create
@contact = Contact.new(params[:contact])
@customer = @contact.customer
@contact.save
respond_to do |format|
format.js
end
end
Create.js.erb:
$(".contact_list").append("<%= escape_javascript(render @contact)%>");
$('.contact_input:input').val('');
Development.rb:
Myapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
解决方案
I think you have named it Create.js.erb rather than create.js.erb before.
这篇关于模板与一个Ajax请求缺少错误 - 的Rails 3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文