首先-事先致歉。我意识到有关此问题还有其他文章,但是我对开发非常陌生,需要更全面的理解和解释。
问题是发送TypeError (no implicit conversion of Symbol into Integer)
作为params
查询的一部分时出现.where
错误。
我具有Twilio集成,并且当我从电话号码收到文本时,我想在数据库的Users
表中查找该电话号码以查看它们是否存在,然后执行一些操作。
以下是我在控制台中看到的参数,这些参数是从Twilio的POST调用中获得的(我删除了敏感或不相关的参数):
Parameters: {"SmsStatus"=>"received", "Body"=>"Blah blah blah", "From"=>"+15555555555"}
这是受到打击的控制器方法:
def incoming_text
user = User.where(phone: params[:From])
if user.present?
url = URI.extract(params[:Body])
if url.present? ### Row #26
end
end
根据我读过的其他线程,我认为问题在于如何传递params[:From]
,但我只是不知道我的数据结构或符号是什么应该通过。我应该阅读的任何文档将不胜感激。
编辑:这是我的users
表的架构:
create_table "users", force: :cascade do |t|
t.string "phone"
t.boolean "confirmed"
end
EDIT2 :真正的问题似乎与此无关。我仍在调查,但我不想浪费别人的时间。
EDIT3 :以下是日志:
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."phone" = ? [["phone", "+15555555555"]]
#<User:0x00007efcedb05400>
Completed 500 Internal Server Error in 8ms (ActiveRecord: 0.8ms)
TypeError (no implicit conversion of Symbol into Integer):
app/controllers/users_controller.rb:26:in `incoming_text'
答案 0 :(得分:0)
您的数据库列buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.30.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
defaultConfig {
applicationId "lk.pooranee.naqdamainmenu"
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// Executes lint checks from the ':lint' project at build time.
lintChecks project(':lint')
// Packages lint checks from the ':lintpublish' in the published AAR.
lintPublish project(':lintpublish')
}
implementation fileTree(include: 'Parse-*.jar', dir: 'libs')
implementation('com.crashlytics.sdk.android:crashlytics-ndk:2.1.0@aar') {
transitive = true;
}
implementation 'androidx.appcompat:appcompat:1.0.2'
}
的类型似乎为phone
,您是否尝试过将Integer
强制转换为整数?
更新后,它看起来像:
params[:From]
def incoming_text
user = User.where(phone: params[:From].to_i)
if user.present?
...
end
end
也会自动去除“ +”号