Big Al Ruby Newbie
Big Al Ruby Newbie

Reputation: 834

How to Accept POST XML to Rails Controller

I have a web service that will be sending a POST to my site in the form of XML i am trying to figure out how to actually receive that XML data.

This will not be a file it will be a POST request of data

I can set up a route for it to post to but how can i caputure the info and send it to nokogiri so i can parse it

post URL is

website.com/post_everywhere/create_account

Routes:

resources :post_everywhere do
  post :create_account
end

controller:

class PostEverywhereController < ApplicationController
  def create_account

    /**** How do i capture the info here ****/

  end
end

Sample Data:

<PELoadPostings>
    <PostingAccount>
        <UserName></UserName>
        <Password></Password><!-- for post free without account, UserName and Password are not set -->
        <ContactName></ContactName>
        <ContactPhone></ContactPhone>
        <ContactFax></ContactFax>
        <ContactEmail></ContactEmail>
        <CompanyName></CompanyName>
        <UserID></UserID><!-- for posting with account ContactName, ContactPhone, ContactFax, CompanyName, and UserID are not set -->
    </PostingAccount>
    <PostLoads><!-- for removes this would be a RemoveLoads tag -->
        <load><tracking-number>493266</tracking-number><origin><city>BUENA PARK</city><state>CA</state><postcode></postcode><county></county><country></country><latitude>NaN</latitude><longitude>NaN</longitude><date-start><year>2009</year><month>06</month><day>04</day><hour>12</hour><minute>00</minute></date-start><date-end><year></year><month></month><day></day><hour></hour><minute></minute></date-end></origin><destination><city>CORAL SPRINGS</city><state>FL</state><postcode></postcode><county></county><country></country><latitude>NaN</latitude><longitude>NaN</longitude><date-start><year>2009</year><month>06</month><day>04</day><hour>12</hour><minute>00</minute></date-start><date-end><year></year><month></month><day></day><hour></hour><minute></minute></date-end></destination><equipment><v></v></equipment><loadsize fullload="true"><length>53</length><width></width><height></height><weight>09</weight></loadsize><load-count>1</load-count><stops>0</stops><distance>2600</distance><rate>0.00</rate><comment>DRY VAN</comment></load>
        <load><tracking-number>433693</tracking-number><origin><city>HARBESON</city><state>DE</state><postcode></postcode><county></county><country></country><latitude>NaN</latitude><longitude>NaN</longitude><date-start><year>2009</year><month>06</month><day>03</day><hour></hour><minute></minute></date-start><date-end><year></year><month></month><day></day><hour></hour><minute></minute></date-end></origin><destination><city>DETROIT</city><state>MI</state><postcode></postcode><county></county><country></country><latitude>NaN</latitude><longitude>NaN</longitude><date-start><year>2009</year><month>06</month><day>05</day><hour></hour><minute></minute></date-start><date-end><year></year><month></month><day></day><hour></hour><minute></minute></date-end></destination><equipment><r></r></equipment><loadsize fullload="true"><length>48</length><width></width><height></height><weight>42</weight></loadsize><load-count>1</load-count><stops>0</stops><distance>1</distance><rate>0.00</rate><comment></comment></load>
    </PostLoads>
</PELoadPostings>

Upvotes: 0

Views: 1397

Answers (1)

Stanislav Mekhonoshin
Stanislav Mekhonoshin

Reputation: 4386

In most common way, all request params in rails are available via

params 

hash in controller

So you can fetch your XML via

params[:some_params]

To get within which param name they will be sent, you should contact that third-party service, that will send them.

Or it is possible to see params in development/production.log of Rails app.

Upvotes: 1

Related Questions