- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用本教程将 AJAX 搜索字段添加到我的应用程序:http://www.rymcmahon.com/articles/11
除搜索 JS 字段外,一切正常。它根本不起作用。我的终端控制台中的错误:
ActionView::MissingTemplate (Missing template products/search-results, application/search-results with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder, :haml]
Chrome 中的 JS 控制台
rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:189 GET http://localhost:3000/products?utf8=%E2%9C%93&search=PKP&commit=search 500 (Internal Server Error)
我有 turbolinks v.5 和 rails 5.1.6。
gem 'turbolinks', '~> 5'
gem 'jquery-rails'
gem 'rails', '~> 5.1.6'
好像找不到这个文件:
/products/_search-results.js.rb
$("#product_table").hide();
$("#search-results").html("<%= escape_javascript(render :partial =>'results') %>");
我应该为此添加一些路线吗?感谢您的建议。
以防万一我会添加其他文件:
我的索引方法:
class ProductsController < ApplicationController
def index
if params[:search]
@search_results_products = Product.options_sortable(params)
respond_to do |format|
format.js {render "search-results"}
format.html
end
else
@products = Product.all.paginate(:page =>params[:page], :per_page => 20)
end
end.....
index.html.haml:
.container-fluid
%h2.center
=link_to "Create New Product", new_product_path
=render 'search_products'
%br
%h1.center List of all the Products
#product-table
=render 'table_products'
#search-results
.col-lg-2.offset-md-5
=will_paginate(@product)
我会把其他文件放在这里。
_table.products:
.col-md-8.offset-md-2
%table.frame
%thread
%tr.h2
%th
=link_to "Name", sort: "product_name"
%th
=link_to "Description", sort: "description"
%th Order Name
%th options
%tbody
-@products.each do |product|
%tr
%th.h4
=product.product_name
%th
=product.description
%th
=product.order.name
-if product.order.user == current_user
%th
=link_to 'edit', edit_product_path(product)
||
=link_to 'delete', product_path(product),
remote: true,
method: :delete,
data: { confirm: 'Are you sure?'}
-else
%th
no permission
_results.html.haml
.col-md-8.offset-md-2
%table.frame
%thread
%tr.h2
%th
=link_to "Name", sort: "product_name"
%th
=link_to "Description", sort: "description"
%th Order Name
%th options
%tbody
-@search_results_products.each do |product|
%tr
%th.h4
=product.product_name
%th
=product.description
%th
=product.order.name
-if product.order.user == current_user
%th
=link_to 'edit', edit_product_path(product)
||
=link_to 'delete', product_path(product),
remote: true,
method: :delete,
data: { confirm: 'Are you sure?'}
-else
%th
no permission
和 _search_products.html.haml
.col-lg-4.offset-md-4
=form_tag(products_path, :method => "get", remote: true) do
.form-group.form-control-md
=text_field_tag :search, params[:search], placeholder: 'Enter search text'
=submit_tag 'search', class: "btn"
最佳答案
错误说找不到 /products/search-results.js.rb
这是真的。您的文件名为 /products/_search-results.js.rb
当您在 Controller 中调用 render 'search-results'
它将查找文件名 search-results
- 当您调用 partial =>'results'
它将查找文件名 _results
关于javascript - ActionView::MissingTemplate::缺少模板 - 部分 Java 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52376599/
将 mysite 部署到 VPS 后,我面临此运行时错误。请注意,在我的本地机器上,一切正常。 当我尝试通过 Controller 路由访问任何 View 时,可以说 PostsController#
我在 Rails 中遇到一些路由问题。 我已经为 Project 模型准备了一个模型,所以我使用 rails generate scaffold_controller 生成了一些默认 Controll
当 Google 机器人尝试访问我的某个 Controller 时,我收到此错误消息。 ActionView::MissingTemplate: Missing template channels/s
我正在测试 Rails Controller 并尝试使用代码执行获取: delete :remove_logs, :id => 3 它始终返回一个 ActionView::MissingTemplat
现在,我不得不承认,我是 Ruby on Rails 的新手,并不是很了解每个概念。我已经安装了 Devise 进行身份验证并遵循了 this guide在我的 View 中包含注册和登录链接。 这是
我的 Rails 应用程序从 Rails 6 升级到 Rails 7 后遇到问题。当我尝试 render_to_string 模板时,我收到 ActionView::MissingTemplate 异
我已经使用 capistrano 部署了我的应用程序在 AWS , 与 nginx和 unicorn .当我打开我的主页时,它是空的。这是我的unicorn日志 Started GET "/" for
在从根路径上的某些 IP 地址进行生产时,我随机收到此错误。 rails 应用程序不支持格式 :formats=>[:gif, "image/x-xbitmap", :jpeg, "image/pjp
我收到一个我无法弄清楚的错误: ActionView::MissingTemplate (Missing template cluster/delete_stuff.erb in view path
我有一个为我的主页提供服务的操作。它在正常访问时工作正常(即由网络浏览器中的用户访问),但是当被特定的网络爬虫访问时,它会抛出以下错误: A ActionView::MissingTemplate
我有一个 Rails 3.2 项目。我还使用 haml 作为我的模板引擎,但我决定使用 slim 而不是 haml。所以我用 slim 重写了一些 View 。但是当我将此更改推送到服务器时,我在生产
我有一个简单的角轨应用程序,我正在尝试将其连接起来。 这是我的 Rails Controller : class ItemsController false } end end
我正在尝试进行 ajax 调用,但我不想返回任何数据,或者可能只返回 200。 我的错误是 ActionView::MissingTemplate (Missing template .... 我在
我想使用本教程将 AJAX 搜索字段添加到我的应用程序:http://www.rymcmahon.com/articles/11 除搜索 JS 字段外,一切正常。它根本不起作用。我的终端控制台中的错误
在我的一个 Controller 中,我有以下代码: respond_to do |format| format.html{ redirect_to :me, :flash => {:error
升级到 Rails 3.1.0 和以下版本后 David Rice's instructions ,奇怪的是,我所有的 Controller 都找不到他们的 View 了。 # rails s # S
我正在尝试在我的 Rails 应用程序上使用 Rsec 测试一些非常简单的东西。 这是spec/controllers/movies_controller_spec.rb中的测试代码 describ
我正在尝试为 Ruby on Rails 开发一个插件,但在渲染 html View 时遇到了问题。我的目录结构如下所示: 文件结构 ---/vendor |---/plugins
我正在尝试使用 Rails 进行 AJAX 调用。该调用是对我 Controller 中的 change_profile 操作的调用。该 Action 的内容如下: def change_profil
我一直在我的日志中看到类似于以下内容的错误。 谁能告诉我为什么我会间歇性地收到这样的错误?是缓存问题吗? 每次我尝试加载关于我们的页面时,它都能完美加载,但每隔几天我的日志中就会出现这样的错误,但它并
我是一名优秀的程序员,十分优秀!