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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
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
Ingo Weiss wrote:> 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
>
>
> --
> Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
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"?>
<thing>
<attra>a</attra>
<attrb>b</attrb>
</thing>
but the create method seems to just ignore attra and attrb.
Any help?
-thanks
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---