1

我是 RoR 的新手。在运行时rails _3.2.13_ s,我收到以下错误消息:

nishant@nishant-Inspiron-1545:~/voylla_website$ rails _3.2.13_ s
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/nishant/.rvm/gems/ruby-1.9.2-p320@voylla/bundler/gems/spree_active_shipping-a85128c2ddd9/lib/spree_active_shipping.rb:2)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/nishant/.rvm/gems/ruby-1.9.2-p320@voylla/bundler/gems/spree_active_shipping-a85128c2ddd9/lib/spree_active_shipping.rb:2)
=> Booting WEBrick
=> Rails 3.1.10 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
/home/nishant/.rvm/gems/ruby-1.9.2-p320@voylla/gems/actionpack-3.1.10/lib/action_dispatch/http/mime_type.rb:101: warning: already initialized constant PDF
[DEPRECATION WARNING] Nested I18n namespace lookup under "activerecord.attributes.order" is no longer supported
[2013-09-26 16:11:20] INFO  WEBrick 1.3.1
[2013-09-26 16:11:20] INFO  ruby 1.9.2 (2012-04-20) [i686-linux]
[2013-09-26 16:11:20] INFO  WEBrick::HTTPServer#start: pid=17154 port=3000


Started GET "/" for 127.0.0.1 at 2013-09-26 16:11:46 +0530
  Processing by HomeController#index as HTML
   (0.3ms)  SHOW search_path
  ScrollerImage Load (1.2ms)  SELECT "scroller_images".* FROM "scroller_images" WHERE "scroller_images"."promotional_content_type" = 'DesignerOfWeek'
Rendered home/welcome.html.erb within layouts/spree_application (31.3ms)
Completed 500 Internal Server Error in 422ms

ActionView::Template::Error (undefined method `link_url' for nil:NilClass):
    9:         sc = sc[0] unless sc.nil?
    10:       %>
    11:        <div class="standby">
    12:          <a href="<%= sc.link_url %>"><img src="<%= sc.url.gsub("images","images0") %>" alt="<%= sc.alt_text %>"></a>
    13:        </div>
    14:     </div>
    15:   <!-- Featured Collection -->
  app/views/home/welcome.html.erb:12:in `block in _b2963a3bf824a09e97c143671f39792f'
  app/views/home/welcome.html.erb:1:in `_b2963a3bf824a09e97c143671f39792f'
  app/controllers/home_controller_decorator.rb:4:in `index'

Rendered /home/nishant/.rvm/gems/ruby-1.9.2-p320@voylla/gems/actionpack-3.1.10/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.8ms)
Rendered /home/nishant/.rvm/gems/ruby-1.9.2-p320@voylla/gems/actionpack-3.1.10/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /home/nishant/.rvm/gems/ruby-1.9.2-p320@voylla/gems/actionpack-3.1.10/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (6.0ms)

有人可以帮我理解并解决这个问题。谢谢

编辑:以下是 app/views/home/welcome.html.erb:

<% cache("welcome_page", :expires_in => 1.day) do %>
<div class="home_page_container">
<div class="container_12">
  <div class="third_row grid_12">
  <!-- Deal of the Day -->
    <div class="grid_4 dod_grid grids">
    <h3><span class="home">Deal of the </span>WEEK</h3>
      <% sc = ScrollerImage.where(:promotional_content_type => "DesignerOfWeek") 
        sc = sc[0] unless sc.nil?
      %>
       <div class="standby">
         <a href="<%= sc.link_url %>"><img src="<%= sc.url.gsub("images","images0") %>" alt="<%= sc.alt_text %>"></a>
       </div>
    </div>
  <!-- Featured Collection -->
    <div class="grid_4 collection_grid grids">
    <h3><span class="home">Featured</span> COLLECTION</h3>
      <% sc = ScrollerImage.where(:promotional_content_type => "FeaturedCollection")
         sc = sc[0] unless sc.nil? %>
         <div class="standby">
           <a href="<%= sc.link_url %>"><img src="<%= sc.url.gsub("images", "images1") %>" alt="<%= sc.alt_text %>"></a>
         </div>
    </div>

  <!-- Get the Look -->
    <div class="grid_4 look_grid grids">
      <h3><span class="home">Get the</span> LOOK</h3>
      <% sc = ScrollerImage.where(:promotional_content_type => "GettheLook")
         sc = sc[0] unless sc.nil? %>
        <div class="standby">
        <a href="<%= sc.link_url %>"><img src="<%= sc.url.gsub("images", "images2") %>" alt="<%= sc.alt_text %>"></a>
        </div>
     </div>
   </div>
   <br />

   <div class="first_row grid_12">
  <!-- Tag Grids x 4 -->
  <h3 class="h3_look"><span class="home">SHOP BY</span> LOOK</h3>
  <% sc = ScrollerImage.where(:promotional_content_type => "Tag") 
     sc.each_with_index { |x,i|
  %>
    <div class="grid_3 tag_grids grids" id="rollover_<%= x.id %>">
      <div class="tag_front" id="rollover_<%= x.id %>">
      <a href="<%= x.link_url%>"><img src="<%= x.url.gsub("images", "images"+(i%3).to_s) %>" alt="<%= x.alt_text %>" /></a>
      <div id="rollover_<%=x.id%>" class="tag_rollover" style="visibility: hidden;">
        <% rb = rollover_blurb(x.alt_text) %>
        <a href="<%= x.link_url%>">Over <%= rb[0].to_s %> designs available starting at <%= rb[1].to_s %>.</a>
      </div>
    </div>
    </div>
    <script>
    $(document).ready(function(){
    $("div.tag_front#rollover_<%= x.id %>").mouseover(function() {
      var rlid = $(this).attr("id")
      if ($("div.tag_rollover#"+rlid).css("visibility") != "visible") {
        $($(this).children()[0]).css("opacity", "0.4");
        $("div.tag_rollover#"+rlid).css("visibility", "visible");
      }
    }).mouseout(function() {
      var rlid = $(this).attr("id")
      if ($("div.tag_rollover#"+rlid).css("visibility") != "hidden") {
        $($(this).children()[0]).css("opacity", "1.0");
        $("div.tag_rollover#"+rlid).css("visibility", "hidden");
      }
    });
    });
    </script>
  <% } %>
  </div>

  <br />
</div>
</div>
<%- content_for(:head) do -%>
  <meta property="fb:page_id" content="141716202609787" />
  <meta name="p:domain_verify" content="8475d705acb964b1874e518347854744"/>
<%end%>

<%end%>
4

1 回答 1

0

这是导致问题的代码:

sc = ScrollerImage.where(:promotional_content_type => "FeaturedCollection")
sc = sc[0] unless sc.nil?

你应该做这样的事情(假设你想要第一个结果):

sc = ScrollerImage.where(:promotional_content_type => "FeaturedCollection").first
if sc
  # your code here
end

请注意,在视图中进行查询是不好的做法。您应该将它们放在您的控制器中,或者更好的是,放在演示者中。

于 2013-09-26T12:32:30.247 回答