How to get XML data into mongodb using Rails 3?
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>')
精彩评论