Controller handles form submit without error but not through curl?
I have built a rails api which simply accepts some parameters from a post,
assigns those parameters to a class, and then does some manipulation such
as splitting a string field. This works fine when I post from a form,
however when I make a post through a console using
`curl http://localhost:3000/api/messages --data
"message[to]=test@test.com&message[from]=test@test.com&message[subject]=sdsdssd&message[body]=sfsdsfdsdfsdf`"
I get the following error
NoMethodError (undefined method `split' for nil:NilClass)
My code is as follows..
module Api module V1
class MessagesController < ApplicationController
respond_to :json
def create
message = Message.new(params[:message])
message.to = message.to.split(',')
Message.to is a string so it works when i submit a form but it has an
issue through curl, any ideas why?
No comments:
Post a Comment