Uninitialized Standing Student :: Net

I am working on rails 3.0.4. I am going to send sms to a specific number after saving the student record. The code that I will discuss below works well in rails 2.X, but on rails 3.0.4 I get an error message:

NameError in StudentsController#create 
uninitialized constant Student::Net 

the 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
+3
source share
1 answer

Make sure you have the appropriate statement requiresomewhere, either in your controller, or, preferably, in your file environment.rbor initializer:

require 'net/http'
+14
source

All Articles