2011-08-24 58 views
0

對於超出這個問題的原因,我需要用JSON響應創建映像時:Apotomo:你如何從另一種格式的另一個視圖呈現HTML格式的狀態/視圖?

<%= 
    raw({ 
    ... 
    :url => @image.url(:width => @width, :height => @height), 
    :edit_link => render({:state => :image_edit_table_cell, :template_format => :html}, @image), 
    # btw, I've also tried passing :format => :html 
    :delete_link => link_to_destroy_image(@image, :remote => true, :path => url_for_event(:destroy, :image_id => @image)), 
    ... 
    }.to_json) 
%> 

然而,在JSON,我想包括一些非常奇特的HTML。爲了包含這一點,我渲染一個狀態/視圖(如你可以在:edit_link部分看到的那樣)。這是image_edit_table_cell.html.haml視圖widget的:

= link_to_edit_image @image, :remote => true 
# ... doesn't really matter - as long as you know this is html.haml 

然而,當我創建一個圖像,而JSON呈現,我得到一個Missing template錯誤:

ActionView::Template::Error (Missing template cell/rails/image_edit_table_cell with {:handlers=>[:builder, :rjs, :rhtml, :erb, :haml, :rxml], :locale=>[:en, :en], :formats=>[:json]} in view paths "/home/ramon/source/unstilted/app/widgets", "/home/ramon/source/unstilted/app/widgets/layouts" and possible paths image/table/image_edit_table_cellapplication/image_edit_table_cellapotomo/widget/image_edit_table_cellcell/rails/image_edit_table_cell): 
    6:  :caption => @image.caption || "", 
    7:  :text_tag => @image.text_tag(:width => @width, :height => @height), 
    8:  :url => @image.url(:width => @width, :height => @height), 
    9:  :edit_link => render({:state => :image_edit_table_cell, :template_format => :html}, @image), 
    10:  :delete_link => link_to_destroy_image(@image, :remote => true, :path => url_for_event(:destroy, :image_id => @image)), 
    11:  :success => true 
    12: }.to_json) 
    app/widgets/image/table_widget.rb:37:in `image_edit_table_cell' 
    app/widgets/image/table/new_image.json.erb:9:in `_app_widgets_image_table_new_image_json_erb___457172591_99648970_0' 
    app/widgets/image/table_widget.rb:16:in `add_image' 
    app/widgets/image/uploader_widget.rb:22:in `upload' 

好像問題是,因爲我從JSON文件中渲染它,所以它不知道要尋找一個HTML文件(因此它尋找的格式是json。這就是爲什麼你會在第一個塊中看到:template_file => :html選項(我從here得到)以上代碼

我用這些寶石:

  • '軌', '3.0.10'
  • 的 '細胞', '3.6.2'
  • 'apotomo', 「1.1.2」

回答

0

顯然,這是一個Rails問題,而不是Apotomo問題。這answer爲我做到了!關鍵是在呈現HTML視圖之前設置視圖文件中的格式:

<% self.formats = ["html"] %> 
相關問題