Это может быть глупый вопрос, но как мне сделать выбор, чтобы вернуть целое число?
У меня есть это:
<%= select_tag :month, options_for_select([["01 | Janeiro", 1], ["02 | Fevereiro", 2], ["03 | Março", 3], ["04 | Abril", 4], ["05 | Maio", 5], ["06 | Junho", 6], ["07 | Julho", 7], ["08 | Agosto", 8], ["09 | Setembro", 9], ["10 | Outubro", 10], ["11 | Novembro", 11], ["12 | Dezembro", 12]]), {include_blank: true} %>
Контроллер:
def create
@vehicle = Vehicle.new(vehicle_params)
if @vehicle.save
redirect_to @vehicle
else
render 'new'
end
end
def edit
end
def update
if @vehicle.update(vehicle_params)
redirect_to @vehicle
else
render 'edit'
end
end
.
.
.
def vehicle_params
params.require(:vehicle).permit(:month, :year, :version, :kms, :power, :cc, :transmission, :fuel, :category, :seats, :doors, :color, :condition, :warranty, :price, :manufacturer_id, :model_id, {feature_ids: []}, :banner_image, images: [])
end
Журналы:
Started PATCH "/vehicles/6" for 10.0.2.2 at 2018-06-08 14:42:27 +0000
Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by VehiclesController#update as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"lyBWt44ta0VoT3adk38Qc7zniWzwJqX3nv0MNIgiL58TVOaU3K0qaRbNNAsb60lPqtTwlQNjjnZV2rIfcv4xaw==", "vehicle"=>{"manufacturer_id"=>"7", "model_id"=>"30", "kms"=>"57528", "power"=>"116", "cc"=>"4499.0", "version"=>"458 Itália", "transmission"=>"Manual", "fuel"=>"Gásoleo", "category"=>"Coupé", "seats"=>"2", "doors"=>"2", "color"=>"Vermelho", "condition"=>"Usado", "warranty"=>"3", "price"=>"178900", "feature_ids"=>["", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]}, "month"=>"8", "year"=>"2010", "commit"=>"Submeter", "id"=>"6"}
Vehicle Load (1.1ms) SELECT "vehicles".* FROM "vehicles" WHERE "vehicles"."id" = ? LIMIT ? [["id", 6], ["LIMIT", 1]]
↳ app/controllers/vehicles_controller.rb:86
(0.1ms) begin transaction
↳ app/controllers/vehicles_controller.rb:72
Feature Load (1.2ms) SELECT "features".* FROM "features" WHERE "features"."id" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["id", 1], ["id", 2], ["id", 3], ["id", 4], ["id", 5], ["id", 6], ["id", 7], ["id", 8], ["id", 9], ["id", 10], ["id", 11], ["id", 12], ["id", 13]]
↳ app/controllers/vehicles_controller.rb:72
Feature Load (0.3ms) SELECT "features".* FROM "features" INNER JOIN "features_vehicles" ON "features"."id" = "features_vehicles"."feature_id" WHERE "features_vehicles"."vehicle_id" = ? [["vehicle_id", 6]]
↳ app/controllers/vehicles_controller.rb:72
Model Load (0.2ms) SELECT "models".* FROM "models" WHERE "models"."id" = ? LIMIT ? [["id", 30], ["LIMIT", 1]]
↳ app/controllers/vehicles_controller.rb:72
Manufacturer Load (0.2ms) SELECT "manufacturers".* FROM "manufacturers" WHERE "manufacturers"."id" = ? LIMIT ? [["id", 7], ["LIMIT", 1]]
↳ app/controllers/vehicles_controller.rb:72
(0.1ms) commit transaction
↳ app/controllers/vehicles_controller.rb:72
Redirected to http://localhost:3000/vehicles/6
Completed 200 OK in 23ms (ActiveRecord: 3.2ms)
Я полагаю, что проблема в том, что: month является целым числом, а значение, возвращаемое выбором, является строкой...потому что возвращаемое значение не вставлено в столбец ... так, как я могу сделать выборку, возвращающую целое число?
Кроме того, если я делаю это, все работает отлично:
<%= f.number_field :month, min: 1, max: 12, maxlength: 2 %>
Но то, что я действительно хочу, это то, что я имею в выборе.Надеюсь, вы можете помочь мне!
Спасибо!