Confusion in converting Sinatra form to Rails

After finishing Michael H.'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 – >

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

post ‘/search-numbers’ do

client =, 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? ||

local_numbers =
numbers = local_numbers.list(search_params)

unless numbers.empty?
  out = '<html><head><title>Choose a


Choose a number

numbers.each do |number|
out << “”
out << “#{number.friendly_name}”
out << “”
out << “”
out << ‘’
Sorry! Twilio doesn’t have any numbers available that
match those constraints.’
rescue StandardError => e
'Sorry! ’ + e.message + ‘.’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs