[英]Rails partial error missing template even though there is
For some reason the show link throws error while trying to render its partial, even though the partial exists (named _show.html.erb) 由于某些原因,即使部分存在,show链接在尝试渲染其部分时也会引发错误(名为_show.html.erb)
Made no changes to the routes file. 对路由文件未做任何更改。 It simply has the root declaration and
resources :notes
它仅具有根声明和
resources :notes
And I have not deleted the original "show.html.erb" generated by Scaffold.(matters?) 而且我还没有删除Scaffold生成的原始“ show.html.erb”。(问题?)
index.html.erb index.html.erb
<% @notes.each do |note| %>
<% note.title %>
<%= link_to 'Show', note, remote: true, class: "note-show" %>
<% end %>
<div id="note-show">
</div>
_show.html.erb _show.html.erb
<% note.title %>
<% note.body %>
show.js.erb show.js.erb
$('#note-show').html("<%= render :partial => 'show' %>");
notes controller 笔记控制器
class NotesController < ApplicationController
before_action :set_note, only: [:show, :edit, :update, :destroy]
def index
@notes = Note.all.order('created_at DESC')
end
def show
respond_to do |format|
format.js
format.html
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_note
@note = Note.find(params[:id])
end
Error is 错误是
ActionView::MissingTemplate in Notes#show
Showing /home/arjun/rails/notes/app/views/notes/show.html.erb where line # raised:
Missing partial notes/_show, application/_show with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/home/arjun/rails/notes/app/views"
* "/home/arjun/.rvm/gems/ruby-1.9.1-p431/gems/twitter-bootstrap-rails-3.2.0/app/views"
Strangely on some links it simply shows 奇怪的是,它只是显示了一些链接
$('#note-show').html("hello
");
I found this by using the Browser Page Source 我是通过浏览器页面源找到的
What is incorrect here? 这里有什么不对的地方?
在show.js.erb中,您必须转义javascript,(escape_javascript或j)
$('#note-show').html("<%= j render 'show' %>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.