2015-11-22 76 views
0

出於某種原因而試圖呈現其部分的顯示鏈接拋出錯誤,即使局部存在(名爲_show.html.erb)Rails的部分錯誤缺少模板即使有

再沒更改路線文件。它只是有根宣言和resources :notes

而且我沒有刪除由腳手架生成的原始 「show.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

<% note.title %> 
<% note.body %> 

個show.js.erb

$('#note-show').html("<%= render :partial => 'show' %>"); 

筆記控制器

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 

錯誤是

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" 

奇怪的是一些鏈接它只是表明

$('#note-show').html("hello 
"); 

我通過使用瀏覽器頁面發現此頁面源代碼

這裏有什麼不正確?

+0

http://stackoverflow.com/questions/1620113/why-escape-javascript-before-rendering-a -partial – AbM

回答

0

在show.js.erb你要逃跑的javascript,(escape_javascript或j)

$('#note-show').html("<%= j render 'show' %>");