我对rails几乎一无所知,但是这个项目落在我的手上,我必须做一些事情,不是我的运气,它是用铁轨写的!
所以我看了一下代码并尝试模仿我正在工作的这个页面所做的事情,我认为它正在从一个文件夹或某些东西加载一些pdf到div中,不知怎的,我不得不做做同样的事情,但我不知道如何。
结果给了我这个错误:
undefined method `each' for nil:NilClass
和
127: <tr>
128: <td><table width="510" border="0" cellpadding="2" cellspacing="5" bgcolor="#CCCCCC">
129:
130: <% for trofeu_rotax_classificas in @trofeu_rotax_classifica %>
131: <tr>
132: <td width="22" bgcolor="#333333"><div align="center" class="style4">i</div></td>
133: <td width="377" bgcolor="#E4E4E4"><span class="style18"> <%= trofeu_rotax_classificas.titulo %></span></td>
和...
/home/korridas/site/app/views/public/trofeu_rotax.html.erb:130:in `_run_erb_app47views47public47trofeu_rotax46html46erb'
任何想法?
我可以根据您需要解决问题来更新帖子
编辑:
/home/korridas/site/app/views/public/trofeu_rotax.html.erb:130:in `_run_erb_app47views47public47trofeu_rotax46html46erb'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_view/renderable.rb:34:in `send'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_view/renderable.rb:34:in `render'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_view/base.rb:306:in `with_template'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_view/renderable.rb:30:in `render'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_view/template.rb:205:in `render_template'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_view/base.rb:265:in `render'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_view/base.rb:348:in `_render_with_layout'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_view/base.rb:262:in `render'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/base.rb:1250:in `render_for_file'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/base.rb:936:in `render_without_benchmark'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/home/korridas/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/benchmark.rb:308:in `realtime'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/base.rb:1326:in `default_render'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/base.rb:1332:in `perform_action_without_filters'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/filters.rb:617:in `call_filters'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/home/korridas/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/benchmark.rb:308:in `realtime'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/flash.rb:151:in `perform_action'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `send'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `process_without_filters'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/filters.rb:606:in `process'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/base.rb:391:in `process'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/base.rb:386:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/routing/route_set.rb:438:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:87:in `dispatch'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:121:in `_call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.8/lib/active_record/query_cache.rb:29:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.8/lib/active_record/query_cache.rb:29:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.8/lib/active_record/query_cache.rb:9:in `cache'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.8/lib/active_record/query_cache.rb:28:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/string_coercion.rb:25:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/rack-1.1.6/lib/rack/head.rb:9:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/rack-1.1.6/lib/rack/methodoverride.rb:24:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/params_parser.rb:15:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/session/cookie_store.rb:99:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/failsafe.rb:26:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/rack-1.1.6/lib/rack/lock.rb:11:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/rack-1.1.6/lib/rack/lock.rb:11:in `synchronize'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/rack-1.1.6/lib/rack/lock.rb:11:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:106:in `call'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler/thread_handler.rb:142:in `accept_and_process_next_request'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:448:in `start_threads'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:442:in `initialize'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:442:in `new'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:442:in `start_threads'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:441:in `times'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:441:in `start_threads'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:440:in `synchronize'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:440:in `start_threads'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/lib/phusion_passenger/request_handler.rb:205:in `main_loop'
/home/korridas/.rvm/gems/ruby-1.8.7-p374/gems/passenger-4.0.37/helper-scripts/classic-rails-preloader.rb:187
整个html位:
<tr>
<td><table width="510" border="0" cellpadding="0" cellspacing="5" bgcolor="#333333">
<tr>
<td><a href="/trofeu_rotax_classificacoes"><span class="style6">CLASSIFICAÇÕES</span></a></td>
<tr>
<td><table width="510" border="0" cellpadding="2" cellspacing="5" bgcolor="#CCCCCC">
<% for trofeu_rotax_classificas in @trofeu_rotax_classifica %>
<tr>
<td width="22" bgcolor="#333333"><div align="center" class="style4">i</div></td>
<td width="377" bgcolor="#E4E4E4"><span class="style18"><%= trofeu_rotax_classificas.titulo %></span></td>
<% unless(trofeu_rotax_classificas.file.blank?) %>
<td width="91" bgcolor="#FF0000"><div align="center"><span class="style5"><%= link_to("download PDF", trofeu_rotax_classificas.file.url, :class => "style5") %></span></div></td>
<% end %>
</tr>
<% end %>
</table></td>
</tr>
</tr>
</table></td>
</tr>
还有这些文件,我认为代码参考:
<table>
<tr>
<th class="th_id"><span>Id</span></th>
<th>Titulo</th>
<th class="th_actions"><span>Actions</span></th>
</tr>
<% @trofeu_rotax_classificas.each do |trofeu_rotax_classificas| %>
<tr>
<td class="td_id"><%=h trofeu_rotax_classificas.id %></td>
<td><%=h trofeu_rotax_classificas.titulo %></td>
<td>
<%= link_to image_tag('cms/edit.png'), trofeu_rotax_classificas_path(trofeu_rotax_classificas) %>
<%= link_to image_tag('cms/delete.png'), trofeu_rotax_classificas, :confirm => 'Tem a certeza que deseja apagar este item?', :method => :delete %>
</td>
</tr>
<% end %>
</table>
和
<% form_for(@trofeu_rotax_classificas, :html => { :multipart => true }) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :titulo %><br />
<%= f.text_field :titulo %>
</p>
<p>
<%= f.label :file %><br />
<%= link_to("Ficheiro", @trofeu_rotax_classificas.file.url) unless(@trofeu_rotax_classificas.file.blank?) %><br />
<%= upload_column_field 'trofeu_rotax_classificas', 'file' %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
和...
<%= render(:layout => "form") %>
答案 0 :(得分:0)
错误
undefined method `each' for nil:NilClass
表示您正在调用每个nil
对象的方法。
在您的情况下,似乎变量@trofeu_rotax_classifica
为nil
,因此您要在controller
答案 1 :(得分:0)
此变量为零:@trofeu_rotax_classificas
。
Rails中的变量在控制器中设置。在您的服务器日志中,应该说Started GET for...
然后Processing by <Controller>#<action>
。
无论出于何种原因,该控制器都不返回变量。 (实例变量,未设置时,默认为nil
)
看起来你可能有PublicController
?如果是这样,可能存在问题所在。