出于此问题的原因,我需要在创建图像时使用JSON进行响应:
<%=
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
视图:
= 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获得了该选项)。
我正在使用这些宝石:
答案 0 :(得分:0)
显然,这是一个Rails问题,而不是Apotomo问题。这answer为我做了!关键是在渲染html视图之前在视图文件中设置格式:
<% self.formats = ["html"] %>