新手问题 你们有没有遇到过这种问题"undefined method `cast_type' for"?

msl12 · 2016年04月19日 · 最后由 msl12 回复于 2016年04月19日 · 3937 次阅读

刚刚升级了 rails 5

然后就遇到了这个问题:

undefined method `cast_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x000000048d37f0>

Extracted source (around line #35):
    @users=User.same_group_with(current_user)
    @plans=Plan.where(user_id: @users.ids).search_plans_for_selected_time($time).includes(:user).order(:created_at)
    @[email protected](page: params[:page], per_page: 10, total_entries: @plans.count).to_a
   else
    @plans=Plan.search_plans_for_selected_time($time).includes(:user).order(:created_at)
    @[email protected](page: params[:page], per_page: 10, total_entries: @plans.count).to_a

具体的错误提示:

Started GET "/plans" for 127.0.0.1 at 2016-04-19 16:21:44 +0800
Processing by PlansController#index as HTML
  User Load (1.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 9], ["LIMIT", 1]]
   (0.3ms)  SELECT "users"."id" FROM "users" WHERE "users"."tag" IN (2, 0)
   (0.4ms)  SELECT COUNT(*) FROM "plans" WHERE "plans"."user_id" IN (1, 9) AND (created_at between '2016-04-15 16:00:00' and '2016-04-16 16:00:00')
  Plan Load (0.5ms)  SELECT  "plans".* FROM "plans" WHERE "plans"."user_id" IN (1, 9) AND (created_at between '2016-04-15 16:00:00' and '2016-04-16 16:00:00') ORDER BY "plans"."created_at" ASC LIMIT $1 OFFSET $2  [["LIMIT", 10], ["OFFSET", 0]]
missed ids -> [] | hitted ids -> [9]
Completed 500 Internal Server Error in 30ms (ActiveRecord: 2.3ms)



NoMethodError (undefined method `cast_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x000000048d37f0>):

app/controllers/plans_controller.rb:35:in `index'
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.3ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.7ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.6ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (19.4ms)
DEPRECATION WARNING: Accessing mime types via constants is deprecated. Please change `Mime::HTML` to `Mime[:html]`. (called from const_missing at /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_dispatch/http/mime_type.rb:52)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.7ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.5ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.6ms)
DEPRECATION WARNING: Accessing mime types via constants is deprecated. Please change `Mime::WEB_CONSOLE_V2` to `Mime[:web_console_v2]`. (called from const_missing at /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_dispatch/http/mime_type.rb:52)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (18.1ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.2ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.4ms)
  Rendered /home/moshenglong/.rvm/gems/ruby-2.3.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (34.0ms)

然后我发现只要删除了 tmp 文件夹里的cache文件夹,再刷新一下页面就好了

但是下次再需要用到缓存的时候,就会继续出现undefined methodcast_type' for`这个问题..

有没有遇到过这问题的同志呢?你们怎么解决的

先暂时换回原来的 rails 4.2 用着先.. 😢

是的,这个 API 变了

#2 楼 @huacnlee 好吧,我研究下 ruby-china 怎么解决这个问题的

需要 登录 后方可回复, 如果你还没有账号请 注册新账号