Ani*_* Sg 3 ruby nameerror uninitialized-constant ruby-on-rails-3
我正在使用rails 3.0.4.我打算在保存学生记录后将短信发送到特定号码.我在下面提到的代码在rails 2.X中运行良好,但在rails 3.0.4上,我收到一个错误:
NameError in StudentsController#create
uninitialized constant Student::Net
Run Code Online (Sandbox Code Playgroud)
码:
def send_welcome_sms
url=URI.parse("http://webaddress.com");
#error occuring at this point
request = Net::HTTP::Post.new(url.path)
message = "message goes here"
request.set_form_data({'username'=>"abc", 'password'=>"xyz", 'to'=> "some number", 'text'=> "#{message}", 'from'=> "someone"})
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
# If U are Behind The Proxy Comment Above Line And Uncomment Below Line, Give The Proxy Ip & Port
#response = Net::HTTP::Proxy("PROXY IP", PROXYPORT).new(url.host, url.port).start {|http| http.request(request) }
case response
when Net::HTTPSuccess
puts response.body
else
response.body
response.error!
end
end
Run Code Online (Sandbox Code Playgroud)
Dyl*_*kow 15
确保require
在控制器中或者最好在environment.rb
文件或初始化程序中的某处具有相应的语句:
require 'net/http'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5161 次 |
最近记录: |