I'm writing an application that manages articles and I'm having a little trouble with the create action. I'm using Sequel to store data. Here is the relevant section of my resource definition:
action :create do
routing { post '' }
response :created
payload do
attribute :title
attribute :content
attribute :published_at
end
end
And here is the relevant section of my controller:
def create
article = Article.create do |article|
article.title = request.payload.title
article.content = request.payload.content
article.published_at = request.payload.published_at
end
response.headers['Content-Type'] = 'application/json'
response.body = article.values
response
end
When I post an article, it gets created in database but the response fails. Here is the error, if you like, I can post the backtrace too:
"message": "wrong number of arguments (1 for 0)"
Any help is much appreciated.
Kind Regards,
Craig Walsh.
--
You received this message because you are subscribed to the Google Groups "praxis-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to praxis-suppor...@googlegroups.com.
To post to this group, send email to praxis-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/praxis-support/6645776b-adc6-4790-a060-896a4a22905b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks Josep that has worked a treat. I'm not sure if this is a related issue but now I get the following error message:
"name": "Praxis::Exceptions::InvalidResponse",
"message": "Response :ok is not allowed for :create"
This is strange because I am returning the :created response in the resource definitions create action. If I change the response to :ok, the error message goes away and everything works as expected. Does this seem backwards to you?
To view this discussion on the web visit https://groups.google.com/d/msgid/praxis-support/f18fa75d-f2a3-4fe0-9342-ce38118b44a5%40googlegroups.com.