开发者

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

开发者 https://www.devze.com 2023-02-08 00:38 出处:网络
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 databa

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!


In your ContentsController add this line at the top:

protect_from_forgery, :except => [:get_some]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号