How to write string params for JSON in rails 4 -


how write strong params json, if have map model want save these records:

{ "map":[   {"lat": "51.088672", "lon": "71.396522", "vibration_level": "300", "time_sent": "07:25:00"},   {"lat": "51.088672", "lon": "71.396453", "vibration_level": "300", "time_sent": "07:25:01"},   {"lat": "51.088829", "lon": "71.396476", "vibration_level": "300", "time_sent": "07:25:14"}   ] } 

i have tried that:

params.require(:map).permit(:lat, :lon, :vibration_level, :time_sent)  params.permit(map: [:lat, :lon, :vibration_level, :time_sent])  params.permit(map: [:lat, :lon, :vibration_level, :time_sent]).require(:maps) 

try hope help.

before_action :parse_json_data_to_params, except: [ # put actions names here otherwise raise error requests ]  def parse_json_data_to_params   params.merge!(activesupport::json.decode(request.raw_post)) end 

and in params permit method.

params.require(:map).permit(:lat, :lon, :vibration_level, :time_sent)  

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -