Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...