I am trying to parse a JSON Object to insert values in table(MySQL). JSON is recived at server but it is unable to read the values to be inserted. Its inserting NULL values. Below is snapshot from my rails console.
Started POST "/lists.json" for 192.168.1.9 at 2013-08-13 11:38:46 +0530
Processing by ListsController#create as JSON
Parameters: {"list"=>[{"amount"=>"120", "status"=>"done", "itemno"=>"w01", "na
me"=>"t01"}]}
WARNING: Can't verify CSRF token authenticity
(1.0ms) BEGIN
SQL (1.0ms) INSERT INTO `lists` (`amount`, `itemno`, `name`, `status`) VALUES
(NULL, NULL, NULL, NULL)
(103.0ms) COMMIT
The Create method in my lists_controller.rb is as below
def create
lists = params[:list].collect{|key,list_attributes| List.new(list_attributes)}
all_list_valid = true
lists.each_with_index do |list,index|
unless list.valid?
all_list_valid = false
invalid_list = lists[index]
end
end
if all_list_valid
@lists = []
lists.each do |list|
list.save
@lists << list
end
format.html { redirect_to @list, notice: 'List was successfully created.' }
format.json { render json: @list, status: :created, location: @list }
else
format.html { render action: "new" }
format.json { render json: @list.errors, status: :unprocessable_entity }
end
end
I am not sure why it is taking NULL values even though "Parameters" seems to have correct values. Please advise . Thanks.