我正在尝试将我的rails 3.0应用程序升级到3.1(然后再升级到3.2),但我遇到了以下问题:
在我的控制台中:
1.9.3p0 :026 > Film.search('art')
Sphinx Query (6.6ms) art
Sphinx Found 323 results
Course Load (2.1ms) SELECT `films`.* FROM `films` WHERE `films`.`id` IN (159, 234, 237, 238, 239, 241, 259, 274, 310, 427, 671, 786, 859, 1015, 1037, 1104, 1108, 1351, 1547, 1622)
=> [#<Film id: 159, name: .......
但如果我尝试在视图中执行以下操作,
def index
...
logger.debug ">>>>>>>>>>>>>> 1"
logger.debug ">>>>>>>>>>>>>> " + Course.search('art').inspect
logger.debug ">>>>>>>>>>>>>> 2"
...
end
我得到以下日志:
Started GET "/films" for 127.0.0.1 at 2012-02-07 16:29:33 -0800
Processing by FilmssController#index as HTML
>>>>>>>>>>>>>> 1
Sphinx Query (5.1ms) art
Sphinx Found 323 results
Film Load (1.4ms) SELECT `films`.* FROM `films` WHERE `films`.`id` IN (159, 234, 237, 238, 239, 241, 259, 274, 310, 427, 671, 786, 859, 1015, 1037, 1104, 1108, 1351, 1547, 1622)
Completed 500 Internal Server Error in 281ms
NoMethodError (undefined method `type' for nil:NilClass):
app/controllers/films_controller.rb:52:in `index'
如果在控制器中,我用 @films = Film.where('id&lt; 100')替换 @films = Film.search('art') ,然后我得到:
ActionView::Template::Error (undefined method `type' for nil:NilClass):
1:
2: <div class="item" <%= "style=\"background:transparent url('/images/corner-official-33px.png') no-repeat 653px 1px;\"" if film.producer.is_official? %>>
3: <div class="left_column" style="margin-right:10px;">
4: <%= image_tag film.producer.picture_url(:avatar), :size => '56x56' %>
5: <%= link_to film.producer.short_name, producer_path(film.producer), :style => "font-size:11px;" %>
app/views/films/_film_item.html.erb:2:in `_app_views_films__film_item_html_erb___118918907990974304_70130279039420'
app/views/films/_films.html.erb:35:in `_app_views_films__films_html_erb__4156916298260674623_70130271252280'
app/views/films/index.html.erb:7:in `_app_views_films_index_html_erb___995304993819916692_70130270918920'
app/controllers/films_controller.rb:56:in `block (2 levels) in index'
app/controllers/films_controller.rb:55:in `index'
我现在一直在调查这个问题几个小时,但仍然不确定是什么问题,也不知道从哪里开始调试......
我安装了以下宝石: rails(3.2.1,3.2.0,3.1.3,3.0.9) 思考 - 狮身人面像(2.0.11,2.0.10) will_paginate(3.0.3,3.0.2)
更新
在玩完之后,我意识到如果我在执行搜索或where子句之前放入'logger.debug Film.first.inspect',代码运行正常......不知道为什么! !有什么想法吗?