开发者

uninitialized constant Student::Net

I'm working on rails 3.0.4. I intend to send out sms to a particular number after saving students record. The code that I'm gonna mention below worked well in rails 2.X, but on rails 3.0.4, I get an error:

NameError in StudentsController#create 
uninitialized constant Student::Net 

Code:

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'=> "som开发者_C百科e 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


Make sure that you have the appropriate require statement somewhere, either in your controller, or preferably, in your environment.rb file or an initializer:

require 'net/http'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜