一、项目中使用了未安装的插件,
MissingSourceFile (no such file to load -- google_chart): app/controllers/home_page/home_controller.rb:4
通过安装插件来解决
gem install google_chart
NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each): app/controllers/search_controller.rb:49:in `index'
这个是最常见的错误,根据错误信息可以知道,调用each方法的对象为空,只要检查each前的对象即可
nil.each
三、路径错误
项目中不能找到与输入相匹配的路径,一般是手误或路径与routs中的不匹配
ActionController::RoutingError (No route matches "/albums" with {:method=>:get}):
四、模板错误
与第二个类似,也是对象为空导致的。
ActionView::TemplateError (You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]) on line #2 of app/views/layouts/home_page/_webinfo.html.erb: 1: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 2: <title><%= show_page_title(@page_title,@HomePageLink) %></title> 3: <meta name=GOOGLEBOT content="index,follow"> 4: <meta name="robots" content="index,follow"> 5: <%- unless @page_keyword==nil -%>
五、数据库,字段错误
数据库中没有所用到的数据库的字段
ActiveRecord::UnknownAttributeError (unknown attribute: sell_id):
ActionView::TemplateError (undefined method `click_number' for #<Admin::Advertisement:0x662f218>) on line #14 of app/views/admin/manage_ad/_list_ads.html.erb: 11: <td><%= ad.page_controller %></td> 12: <td><%= ad.position %></td> 13: <td><%= ad.url %></td> 14: <td><%= ad.click_number %></td> 15: <td><%= link_to "鍒犻櫎", {:action => :destroy, :id => ad}, :method => :delete, :confirm => "浣犵‘瀹氳鍒犻櫎杩欐潯骞垮憡涔堬紵" %></td> 16: <td><%= link_to "缂栬緫", {:action => :edit, :id => ad} %></td> 17: </tr>
七、运行错误
这也是一个常见错误,取id的值的对象为空
下面这个例子:
控制器:
ad.user_id = Register::User.find_by_username(params[:user_username]).id
RuntimeError (Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id): app/controllers/admin/manage_ad_controller.rb:30:in `create' C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' C:/Ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' C:/Ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' C:/Ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' C:/Ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'
八、缺少end
这种错误一般出现在模板里,使用控制语句或循环语句时忘记了end
ActionView::TemplateError (compile error D:/cetcit/app/views/admin/data_stats/index.erb:30: syntax error, unexpected kENSURE, expecting kEND D:/cetcit/app/views/admin/data_stats/index.erb:32: syntax error, unexpected $end, expecting kEND) on line #30 of app/views/admin/data_stats/index.erb:
ActionView::TemplateError (undefined method `images' for #<ActionView::Base:0xebbb88c>) on line #4 of app/views/admin/data_stats/index.erb: 1: <%# 2: # To change this template, choose Tools | Templates 3: # and open the template in the editor. 4: %> 5: <%=javascript_include_tag "admin/data_stat/jquery","admin/data_stat/jquery.ingrid","admin/data_stat/jquery.cookie"%> 6: <%= stylesheet_link_tag 'admin/data_stat/ingrid'%> 7: <%= images 'data_stat' %>
十、方法未知
ActionController::UnknownAction (No action responded to select_data(data). Actions: admin_role_required, hot_tags, index, select_data, sponsor_link, and user_role_required): C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' C:/Ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' C:/Ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' C:/Ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' C:/Ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'