Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

ruby-on-rails-5 - ActionController :: Parameters将整数转换为字符串(ActionController::Parameters converts integer to string)

i have defined user_params in rails 5, like this:

(我已经在rails 5中定义了user_params,如下所示:)

    def training_plan_params
      params.require(:training_plan).permit(:training_plan_id, :sport_id, :distance,
        lastTrainingStatus:[:duration,:reps,:type,:level],
        trainings: [:text, :order, :level],modified:[:level,:duration])
    end

but when i send the params to rails, like this:

(但是当我将参数发送到rails时,如下所示:)

{ training_plan: { sport_id: 2, distance: 900 } }

it doesn't retrieve the distance in the controller as integer, like this:

(它不会以整数形式检索控制器中的距离,如下所示:)

=> <ActionController::Parameters {"sport_id"=>"2", "distance"=>"900"} permitted: true>

=> training_plan_params[:distance]
=> "900"

is there a way to keep its type and not converts it to string?

(有没有办法保持其类型,而不是将其转换为字符串?)

  ask by socertis translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...