How can I stop rails validating xml?

Posted by Andrei T. Ursan on Stack Overflow See other posts from Stack Overflow or by Andrei T. Ursan
Published on 2010-04-20T00:51:29Z Indexed on 2010/04/20 0:53 UTC
Read the original article Hit count: 492

Filed under:
|
|

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: &quot;600&quot;
        background_color: white
        width: &quot;800&quot;
      type: text/smil-basic-layout
  body: !map:HashWithIndifferentAccess 
    par: !map:HashWithIndifferentAccess 
      text: !map:HashWithIndifferentAccess 
        left: &quot;33&quot;
        begin: &quot;33&quot;
        dur: &quot;33&quot;
        val: 34343434343434343aaaaaaa
        height: &quot;33&quot;
        width: &quot;33&quot;
        top: &quot;33&quot;

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 ...

© Stack Overflow or respective owner

Related posts about rails

Related posts about Xml