接收错误消息无法将符号转换为整数

时间:2012-09-18 04:35:04

标签: ruby-on-rails database

我的twilio应用程序的控制器中有以下代码,因为您将在“id = user ...”行中看到错误:

class CallsController < ApplicationController
def play
    user = Refugee.find_all_by_cell_number(params[:id]) && Student.find_all_by_cell_number(params[:id])
    id = user[:last_class].to_i
    lesson = RecordedLesson.find(id).next
    user[:last_class] = lesson.id
    user.save
    @audio_lesson_url = lesson.sound_file.url
    render :action => "play.xml.builder", :layout => false
end
end

然后我收到以下错误消息

    app/controllers/calls_controller.rb:7:in `play'=2012-09-18T04:00:13+00:00 app[web.1]: TypeError (can't convert Symbol into Integer):

尽管我运行了以下迁移

    class ChangeLastClassOfStudents < ActiveRecord::Migration
      def change
        change_column :students, :last_class, :integer, :null => true

      end
    end

1 个答案:

答案 0 :(得分:0)

假设您的用户对象有效并响应last_class方法。你尝试过这样做吗?

id = user.last_class

由于你的last_class已经是一个属性和一个整数,所以没有理由将其转换。