Q:

how to use Twilio SMS params[:Body] to search a rails database

Hello I'm trying to search my database to find a recipe from the body of an SMS using twilio.  Here is my code so far in the controller 
 def process_sms
    @recipe = Recipe.find_by(params[:title])
    render 'process_sms.xml.erb', :content_type => 'text/xml'
  end

and my routes:
root          'recipes#index'
  devise_for    :users
  resources     :recipes
  post          'twilio/voice' => 'twilio#voice'
  post          'twiliosms/send_sms' => 'twiliosms#send_sms'
  match         'twiliosms/process_sms' => 'twiliosms#process_sms', via: :all

I'd like to be able to search for the Recipe title from the SMS and render some xml.  The current implementation keeps sending back the same recipe over and over again.  I think it has something to do with not passing the twilio params[:Body] in the same controller action and using that to match a recipe(params[:title]) but not completely sure.  Any help would be appreciated. Thanks!

A:

Twilio developer evangelist here.
You've mentioned params[:Body], which is the parameter in which the text from the SMS message will be, however you are using params[:title] to search with. In the context of an incoming webhook from Twilio, params[:title] will be nil, so I would guess your recipe that is being returned has no title.
I think you should be using:
def process_sms
  @recipe = Recipe.find_by(title: params[:Body])
  render 'process_sms.xml.erb', :content_type => 'text/xml'
end

Let me know if that helps at all.
[edit]
Updated call to find_by

