3

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'=> "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
Mischa
  • 42,876
  • 8
  • 99
  • 111
Aniruddha Sg
  • 41
  • 1
  • 5

1 Answers1

15

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'
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201