【问题标题】:Unable to autoload constant Featured_image, expected C:/Sites/pickyourchoice/app/models/featured_image.rb to define it无法自动加载常量 Featured_image,需要 C:/Sites/pickyourchoice/app/models/featured_image.rb 来定义它
【发布时间】:2015-11-21 13:53:57
【问题描述】:

我的 rails 应用程序中有一个模型 Featured_images,在我的视图页面中,我需要显示与此模型表一起存储的所有数据。 在我的控制器中,我有一个名为 index 的方法

def index
  @featured_images = Featured_image.all
end

在我看来

<% @featured_images.each do |h| %>
    <div class="item">
        <%=image_tag h.pg_images.url(:medium), :class=>'img-responsive' %>
    </div>
<% end %>

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4.1


    【解决方案1】:

    你需要使用

    @featured_images = FeaturedImage.all
    

    而不是

    @featured_images = Featured_image.all
    

    你的模型应该是这样的

    class FeaturedImage < ActiveRecord::Base
    
    end
    

    【讨论】:

    • 您好,感谢您的回答,我已经尝试过了。现在没有错误,但在视图中没有数据。
    • 是因为我没有为 features_images 模型提供任何强大的参数定义吗?
    • 可能是,你可以用控制台查看表中的数据吗?
    • 我在表中的数据库中有数据。当我在检查元素时,它显示它没有进入循环。
    • 您用于图像处理的东西,即载波或回形针。
    猜你喜欢
    • 2019-04-10
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    相关资源
    最近更新 更多