【发布时间】:2014-01-14 19:30:02
【问题描述】:
我正在尝试在对话框中显示信息。我希望从视图(模板)中加载此类信息。问题是,当我使用时
<%= render template:'panels/product_specifications' %>
它会尝试加载信息,但是由于我在视图中使用了控制器中定义的全局变量,并且控制器没有被执行,所以它抛出了我:
undefined method `banner_image_with_arrows_filename' for nil:NilClass
Extracted source (around line #2):
1:
2: - banner_image = "banners/panels/#{@panel.banner_image_with_arrows_filename}"
3: #image-info
4: %table
5: %tr
@panel 变量在控制器中定义:
def load_panel
@panel = Panel.find_or_build_from_id(params[:id])
if !@panel.available_in_market?(market)
add_flash_notice(t("pages.panel.text.not_available_in_market", :market => market.name), true)
end
end
在before_filter。
我也尝试过render partial:'panels/products_specifications(首先使用下划线'product_specifications.html.erb'),render action:'panels/product_specifications', controller:'product_specifications 有不同的错误。
如何在执行控制器的情况下从另一个加载部分视图或视图?
编辑:
为了给你一个大图景,我想做的是向用户(当他将鼠标移到链接上时)显示一个对话框,其中预览了他点击该链接时将看到的内容。
【问题讨论】:
-
你在哪里打电话
render_to_string?在视图中? -
render partial:'panels\products_specifications这是正确的道路吗?应该是render partial: 'panels/products_specifications' -
@polarblau:抱歉,当我发布问题时,我一定很困。我只用
render和render partial: 'panels/products_specifications'更正了 ir,因为我在代码中就是这样做的
标签: ruby-on-rails templates views partials