我想将两个值连接成一个字符串

时间:2019-06-26 15:43:44

标签: ruby-on-rails

我在弦中有两个不同的收缩压和舒张压读数。当这两个值来自前端时,我会将它们存储在单个字符串中,例如,如果systolic ='120'和diastolic = '80',我想要bp='120/80'

module Api
  module V1
    module CheckinMachine
      class BpsController < ApplicationController
        include MachineError
        before_action :authenticate_user!

        def create
          raise BatteryNotFunctionalError if battery_functional?
          # user = User.find_by!(bp_machine_imei: params[:imei])
          health_reading = current.health_readings.create!(key: :blood_pressure, value: bp_value)
          Solera::PostActivityApi.call(user,
                                       bp,
                                       health_reading.solera_activities.new)
          head :ok
        rescue ActiveRecord::RecordNotFound => _e
          render_machine_error and return
        end

        def show
          puts params
        end

        private

        def bp
          {
            systolic_blood_pressure: params[:systolic],
            diastolic_blood_pressure: params[:diastolic]
          }
        end
      end
    end
  end
end

这就是我尝试过的方法,我该怎么做才能使其完全符合我的要求

like bp ='120/80'

1 个答案:

答案 0 :(得分:1)

由于您已经将2个值存储在params中,所以这非常简单:

#{x}

请记住,Ruby使用x语法(其中x = "apples" y = 5 string = "I have #{y} units of #{x} to sell you" puts(string) > "I have 5 units of apples to sell you" 是变量值)在字符串中进行了变量替换。

例如:

#parent img {
position: absolute;
top:0;
left:0;
height: auto;
width: calc(100% + 10px);