ruby on rails - Params not defined -
i'm doing api application, have post route:
{ "user_id":"1" }
this route calls method of controller:
def shouts puts(params) @user = user.find_by_id(params[:user_id]) render json: {status: 0, message: "sucess", data: @user.yells} end
what happens when test postman on machine runs smoothly. , possible accompany puts
terminal:
started post "/api/shouts" 10.0.2.2 @ 2016-01-27 16:11:16 +0000 cannot render console 10.0.2.2! allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 processing api::yellscontroller#shouts */* parameters: {"user_id"=>"1", "yell"=>{"user_id"=>"1"}} {"user_id"=>"1", "controller"=>"api/yells", "action"=>"shouts", "yell"=>{"user_id"=>"1"}} user load (0.3ms) select "users".* "users" "users"."id" = $1 limit 1 [["id", 1]] yell load (0.5ms) select "yells".* "yells" "yells"."user_id" = $1 [["user_id", 1]] category load (0.4ms) select "categories".* "categories" inner join "categories_yells" on "categories"."id" = "categories_yells"."category_id" "categories_yells"."yell_id" = $1 [["yell_id", 1]] completed 200 ok
however when testo on machine within same network, stop comes nothing, or coming:
started post "/api/shouts" 10.0.2.2 @ 2016-01-27 16:09:04 +0000 cannot render console 10.0.2.2! allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 processing api::yellscontroller#shouts */* {"controller"=>"api/yells", "action"=>"shouts"} user load (0.3ms) select "users".* "users" "users"."id" null limit 1 completed 500
anyone know can happening? how fix? it's have set in vagrant machine? or on server? or ruby on rails?
update
i discovered wrong in call on postman forgetting put on content-type header = aplicatio / json.
is there way of pre configure in ruby on rails? put calls have same header.
you can add in application controller:
before_filter :set_format def set_format request.format = 'json' # or whatever want end
or in routes.rb
resources :shouts, defaults: { format: 'json' }
Comments
Post a Comment