How can I stop rails validating xml?
- by Andrei T. Ursan
I'm submitting to a rails webservice the following message:
xmlPostData = "<message>
                   <message-text>" + MESSAGE_WITH_XML  + "</message-text>
                   <name>" + subject + "</name>
                   <f1>" + toPhone + "</f1>
                   <f2>" + fromPhone + "</f2>
               </message>";
The problem is the the  field with contain a text with  XML data, is a workaround but I need to be able to submit that xml to the db and get it from there.
Can I stop rails validating and replacing my xml in json format?
this is how it looks:
    --- !map:HashWithIndifferentAccess 
smil: !map:HashWithIndifferentAccess 
  head: !map:HashWithIndifferentAccess 
    layout: !map:HashWithIndifferentAccess 
      root_layout: !map:HashWithIndifferentAccess 
        height: "600"
        background_color: white
        width: "800"
      type: text/smil-basic-layout
  body: !map:HashWithIndifferentAccess 
    par: !map:HashWithIndifferentAccess 
      text: !map:HashWithIndifferentAccess 
        left: "33"
        begin: "33"
        dur: "33"
        val: 34343434343434343aaaaaaa
        height: "33"
        width: "33"
        top: "33"
And this is the ruby method from the rails webservice:
# POST /messages
  # POST /messages.xml
  def create
    @message = Message.new(params[:message])
    respond_to do |format|
      if @message.save
        flash[:notice] = 'Message was successfully created.'
        format.html { redirect_to(@message) }
        format.xml  { render :xml => @message, :status => :created, :location => @message }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @message.errors, :status => :unprocessable_entity }
      end
    end
  end
Is a workaround but for the moment this has to work ...