jyoseph
jyoseph

Reputation: 5455

Rails - How to allow 3rd party service to POST to my rails app?

I'm new to rails, so this might seem like a dumb question. I want to allow a 3rd party site to post data to a specific URL on my site. I want to take the data, format it and add a record to my database.

I've done this in other languages, but have no idea how to do this in rails, or even where to start. But I'll take my best stab and hope someone can steer me in the right direction.

Add this to my routes:

match 'third_party_post_here', :to => 'contents#get_some'

Add a function to my contents_controller.rb

  def get_some

    content = Content.new

     # these are the fields that will be posted
        #   method
        #   title
        #   message
        #   location
        #   media
        #   raw_message
        #   trigger

  end

You can see there are specific fields that I'd be expecting. So would I do something like this?:

content = Content.new
content.name = Content.find(params[:title])

And then after I've retrieved all of the data I need then do content.save. I'm not sure if I'm going down the right track or not? Really looking to do this the most "rails way" possible. Thanks in advance for any pointers or advice on best practices!

Upvotes: 1

Views: 181

Answers (1)

charley handsome
charley handsome

Reputation: 46

In your ContentsController add this line at the top:

protect_from_forgery, :except => [:get_some]

Upvotes: 3

Related Questions