After finishing Michael Hartl's tutorial on Rails, I'm trying to build a
call-tracking app with Twilio, to get a sense of things.

So far, I've managed to make an authentication system, a plans system,
integrated stripe, and integrated the creation of Twilio subaccounts
with user signup.

Now, I'm looking to figure out how to get users to search for a phone
number, choose from the list, and buy the phone number.

They have documentation on this here -- >
http://www.twilio.com/docs/howto/search-and-buy

But, the Sinatra is really confusing me. I'm not sure how to separate
the views from the controllers while looking at that code.

Currently, I have 2 relevant models

The User model, which has_many phone numbers.

I tried creating a new controller, the find_numbers controller, that
would do the search for the numbers, and transmit the chosen number to
the phone_numbers controller, but ended up riddled with errors.


Could someone give me pointers on how I would convert the following to
Rails controller/views?


=========================================
We take the user's criteria and search for available phone numbers that
match

post '/search-numbers' do
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'

client = Twilio::REST::Client.new(account_sid, auth_token)

####After here I'm confused!!
search_params = {}
%w[in_postal_code near_number contains].each do |p|
search_params[p] = params[p] unless params[p].nil? ||
params[p].empty?
end

begin
local_numbers =
client.account.available_phone_numbers.get('US').local
numbers = local_numbers.list(search_params)

unless numbers.empty?
out = '<html><head><title>Choose a
number</title></head><body><h3>Choose a number</h3>'
numbers.each do |number|
out << "<form method='POST' action='/buy-number'>"
out << "<label>#{number.friendly_name}</label>"
out << "<input type='hidden' name='PhoneNumber'
value='#{number.phone_number}' />"
out << "<input type='submit' value='BUY' /></form>"
end
out << '</body></html>'
else
'<b>Sorry!</b> Twilio doesn\'t have any numbers available that
match those constraints.'
end
rescue StandardError => e
'<b>Sorry!</b> ' + e.message + '.'
end
end

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 3, '12 at 11:56a
activeOct 3, '12 at 11:56a
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

stepan Parunashvili: 1 post

People

Translate

site design / logo © 2022 Grokbase