开发者

How to get XML data into mongodb using Rails 3?

开发者 https://www.devze.com 2023-03-31 14:13 出处:网络
I\'ve got XML data which I want to be saved in a mongodb. I\'m using RESTClient to perfom a POST on the resource. The HTML status code returns that it was created. However all fields are \"nil\". What

I've got XML data which I want to be saved in a mongodb. I'm using RESTClient to perfom a POST on the resource. The HTML status code returns that it was created. However all fields are "nil". What am I missing? Do I have to convert it to json/bson first? Is it generally possible? I'm using MongoMapper.

I also thought of using a native XML database but I couldn't seem to find any supported by Rails 3. Are there any?

Just the usual stuff in my controller:

def create
  @assessment = Assessment.new(params[:assessment])
  respond_to do |format|

  if @assessment.save
    format.html {redir开发者_StackOverflow社区ect_to(:action => 'list')}   # backdoor for maintanance
    format.xml {render :xml => @assessment, :status => created}
  else
    *omitted*
  end
end


If params[:assessment] is a hash of hashes and arrays, it should work. But if it's straight XML you'll have to have something else parse it first. e.g. Crack Crack::XML.parse('<mydoc>your xml here</mydoc>')

0

精彩评论

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