Skip to main content

Sending Mobile SMS in Ruby on Rails using twilio

Sending Mobile SMS in Ruby on Rails using twilio?

  1. gem install twilio-ruby
  2. In Controller
  3. U need to add the  require 'twilio-ruby'
  4. @account_sid = 'AC3ddc5567a441ea2fdf0a460452599aa6' 
  5. @auth_token = '9aefac893c9c9214770046ecb796d6c8'
  6. @client = Twilio::REST::Client.new(@account_sid, @auth_token)
  7. p @client.account
  8. @client.account.messages.create(from: '+12019044303', to: '+919538947694',body: 'Hello koteshwarrao welcome to my blog')
Notes:
  • From number is nothing but twillo number
  • To Number is from whom u need to send the message
  • Use Only Live credentials only
  • @account_sid is twilio account id
  • @auth_token is twilio auth token
  • Before Sending any message to mobile the mobile number need to be verified to twilio account.

Comments

Popular posts from this blog

Get user accessing ip address in rails?

Get user accessing ip address rails?

request.ip ->returns the ip, whether is is a local proxy ip (localhost address) or not.
*request.remote_ip -> is smarter and gets the ip address of the client outside of local proxies.
3)If you are using apache in front of a mongrel, then remote_ip will return the source address of the request, which in this case will be local host because the Apache web server is making the request, so instead put this in your controller:

@remote_ip = request.env["HTTP_X_FORWARDED_FOR"]

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).?

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).) In rails?


1)change the gemfile in mysql version
 gem 'mysql2'

2)Change to mysql2 version
 gem 'mysql2','0.3.20'

Ruby on rails Interview questions with answers for experience?

1)What is the difference between include and extend?
Ans:
i)Include makes the module methods are available instance of the class.
    1)Not available at the class level
    2)Available at the instance level
ii)extend makes module methods are available class itself.
    1)Not available at the class level
    2)Available at the instance level

  here is a big difference between include and extend in Ruby. Let me show you some code to explain it :
Exampl1:

module Printable
  def self.class_method_x
    p 'class_method_x'
  end

  def instance_method_y
    p 'instance_method_y'
  end
end



class ExtendDocument
  extend Printable
end



class IncludeDocument
  include Printable
end

First round, on the Printable module :

Printable.class_method_x
# => "class_method_x"



Printable.instance_method_y
# => NoMethodError: undefined method `instance_method_y' for Printable:Module

Second round, on ExtendDocument :

ExtendDocument.class_method_x
# => NoMethodError: undefined method `class_method_x…