Hi,
I am POSTing XML-representations of models from Flash to a Rails app.
From the information I have I would expect the following to work:
def create
@message = Message.new(params[:message])
@message.save
end
however, this doesn’t work. Instead I need to do the following:
def create
xml = REXML::Document.new(request.raw_post)
data = Hash.new
xml.elements.each("/message/*"){|prop| data[prop.name] = prop.text}
@message = Message.new(data)
@message.save
end
I would much prever the first version. Why might it now work?
Ingo
Hi,
That is strange, I would have thought that the first one would work.
Are you sure you are running edge and have simply_restful installed ?
I have found that one of the best REST apps to learn from is RestoLog :
http://bgjap.net/code/ruby/ror/
I would go through their code and see where it differs to yours. Their
create statement goes like this :
gets called when for POSTs to /articles
def create
@article = Article.new(params[:article])
@article.user = current_user
@article.save!
respond_to do |format|
format.html do
flash[:notice] = “Article was successfuly created”
redirect_to article_url(@article)
end
format.xml do
headers[“Location”] = article_url(@article)
render :nothing => true, :layout => false, :status => “201
Created”
end
# format.js
end
rescue
respond_to do |format|
format.html { render :action => ‘new’ }
end
end
I hope this puts you in the right direction. Sorry I can’t be of more
help.
Kind Regards
Hamza
I am still having the exact same problem.
When i put this in my controller:
logger.info params[:thing]
@thing = Thing.create(params[:thing])
this is what the log shows:
<?xml version"1.0" encoding="UTF-8"?>
a
b
but the create method seems to just ignore attra and attrb.
Any help?
-thanks
Okay, this appears to be a configuration problem with Mongrel. When I
run Webrick everything works as advertised.
While running Mongrel, if I try to do a Hash.from_xml(params) in the
controller, I get an error message about finding server.xml.
I am working on Windows, so the default configs may be different. I have
spoken with some Mac users where Mongrel works as expected.
-KRat