我有一个 Rails 应用程序,main_controller
用于向我的应用程序的主页提供内容。我想访问一组图像,所以我在控制器中创建了以下方法:
def featured_illustrations
#future implementation: get images where featred == true
@featured_illustrations << Illustration.find(152)
@featured_illustrations << Illustration.find(272)
@featured_illustrations << Illustration.find(275)
respond_to do |format|
format.html
format.json { render :json => @featured_illustrations }
end
end
helper_method :featured_illustrations
我有以下帮手:
module MainHelper
require MainController
@featured_illustrations = MainController.featured_illustrations
end
部分代码如下featured_images
:
<div class="featured">
<% @featured_illustrations.each do |illustration| %>
<!-- somc code to print images -->
<% end %>
</div>
当我尝试查看页面时出现此错误:
uninitialized constant MainHelper::MainController
我之前没有与助手合作过,因此感谢您提供任何指导。谢谢。
更新:我已删除MainHelper
但现在尝试加载页面时出现以下错误:
undefined method `each' for nil:NilClass
Extracted source (around line #2):
1: <div class="featured">
2: <% featured_illustrations.each do |illustration| %>
3: <div class="feature-image" id="feature-one">152</div>
4: <div class="feature-image" id="feature-two">272</div>
5: <div class="feature-image" id="feature-three">275</div>
对原因有什么想法吗?