objective c - TypeError (can't cast ActionController::Parameters to integer) -


i'm trying update longitude , latitude in database based on alert id, when send id database typeerror (can't cast actioncontroller::parameters integer). noticed when submitted submitting string, yet when log parameters in xcode integer.

-(void)updatecordinates{      nsstring *alertid = [defaults objectforkey:@"alertid"];      nsinteger alert_id = [alertid                           integervalue];      nsdictionary *userloc = [[nsuserdefaults standarduserdefaults] objectforkey:@"userlocation"];     nsstring *latitude = [userloc objectforkey:@"lat"];     nsstring *longitude = [userloc objectforkey:@"long"];      // create request.     request = [nsmutableurlrequest requestwithurl:[nsurl urlwithstring:[nsstring stringwithformat:@"http://localhost:3000/api/v1/alerts/%ld/",(long)alert_id]]];      nslog(@"%@", request);       // specify put request     request.httpmethod = @"put";      // how set header fields     [request setvalue:@"application/json" forhttpheaderfield:@"accept"];      [request setvalue:@"application/json" forhttpheaderfield:@"content-type"];      // convert data , set request's httpbody property     nsdictionary *parameters = [[nsdictionary alloc] initwithobjectsandkeys:                                 [nsnumber numberwithinteger:alert_id], @"id",                                 latitude, @"latitude",                                 longitude, @"longitude",                                 nil];     nslog(@"%@", parameters);     nserror *error;     nsdata *postdata = [nsjsonserialization datawithjsonobject:parameters options:0 error:&error];     [request sethttpbody:postdata];      // create url connection , fire request     nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:request delegate:self];     [connection start];  }  module api   module v1     class alertscontroller < applicationcontroller       respond_to :json       wrap_parameters  include: [:user_id,:longitude, :latitude, :id]       skip_before_filter  :verify_authenticity_token       def alert_params           params.require(:alert).permit(:user_id,:longitude, :latitude, :id)       end       def new         @alert = alert.new(alert_params)       end       def create         @alert = alert.create(alert_params)         respond_to |format|             if @alert.save               format.json { render json: @alert.id}             else               format.json { render json: @alert.errors, status: :unprocessable_entity }             end         end       end       def edit         @alert = alert.find(alert_params)       end       def update         @alert = alert.find(alert_params)          respond_to |format|             if @alert.update_attributes(alert_params)               format.json { render json: "alert saved"}             else               format.json { render json: @alert.errors, status: :unprocessable_entity }             end         end       end       def getalerts          alerts = alert.where(:status => "active")         alertarray = array.new()          alerts.each |alert|            distance = triangulate(alert.latitude, alert.longitude, params[:latitude], params[:longitude])            if distance < params[:radius].to_f             testhash = hash.new()             testhash = { "username" =>alert.user.username,"latitude" => alert.latitude, "longitude" => alert.longitude  }             alertarray.push(testhash)           end         end         respond_to |format|           format.json { render json: alertarray}               end       end       end   end end          

try change

@alert = alert.find(alert_params) 

to

@alert = alert.find(params[:id]) 

Comments

Popular posts from this blog

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -