Он не показывает ошибок, чтобы помочь в поиске и устранении проблемы. Я проверил файл базы данных, и он все еще пуст.
Кнопка отправки <div><%= f.submit "Create", class: "btn btn-normal" %></div>
Единственное, что изменяется после отправки, - это адрес. Он изменяется от http://localhost:3000/cars/new
до http://localhost:3000/cars
Все остальное остается прежним. Как это исправить?
Обновлен вопрос со следующим:
Журнал
Started GET "/cars/new" for ::1 at 2020-01-26 14:44:53 +0000
(0.1ms) SELECT sqlite_version(*)
Processing by CarsController#new as HTML
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Rendering cars/new.html.erb within layouts/application
Rendered cars/new.html.erb within layouts/application (Duration: 12.1ms | Allocations: 1210)
[Webpacker] Everything's up-to-date. Nothing to do
Rendered shared/_navbar.html.erb (Duration: 0.7ms | Allocations: 103)
Rendered shared/_message.html.erb (Duration: 0.1ms | Allocations: 17)
Completed 200 OK in 496ms (Views: 471.7ms | ActiveRecord: 1.0ms | Allocations: 15750)
Started POST "/cars" for ::1 at 2020-01-26 14:45:06 +0000
Processing by CarsController#create as HTML
Parameters: {"authenticity_token"=>"Oom+xdVDc0PqSwLbLIEP0R8H6U38+v9ISVql4Fr/0WSxZGSrxzTHccsgghd1U30OugcUBAA1R4BtsB0YigAUtA==", "car"=>{"vehicle_type"=>"Sports", "car_type"=>"Private", "seat"=>"5", "colour_type"=>"Black", "transmission_type"=>"Automatic"}, "commit"=>"Create car"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Rendering cars/new.html.erb within layouts/application
Rendered cars/new.html.erb within layouts/application (Duration: 7.2ms | Allocations: 1144)
[Webpacker] Everything's up-to-date. Nothing to do
Rendered shared/_navbar.html.erb (Duration: 0.2ms | Allocations: 103)
Rendered shared/_message.html.erb (Duration: 0.1ms | Allocations: 17)
Completed 200 OK in 124ms (Views: 114.9ms | ActiveRecord: 0.4ms | Allocations: 14757)
Модель app/models/car.rb
class Car < ApplicationRecord
belongs_to :user
validates :vehicle_type, presence: true
validates :car_type, presence: true
validates :seat, presence: true
validates :transmission_type, presence: true
validates :engine, presence: true
end
Контроллер app/controllers/cars_controller.rb
class CarsController < ApplicationController
before_action :set_car, except: [:index, :new, :create]
before_action :authenticate_user!, except: [:show]
def index
@cars = current_user.cars
end
def new
@car = current_user.cars.build
end
def create
@car = current_user.cars.build(car_params)
if @car.save
redirect_to listing_car_path(@car), notice: "Saved..."
else
render :new, notice: "Something went wrong..."
end
end
def show
end
def listing
end
def pricing
end
def description
end
def photo_upload
end
def features
end
def location
end
def update
if @car.update(car_params)
flash[:notice] = "Saved..."
else
flash[:notice] = "Something went wrong..."
end
redirect_back(fallback_location: request.referer)
end
private
def set_car
@car = Car.find(params[:id])
end
def car_params
params.require(:car).permit(:vehicle_type, :car_type, :seat, :transmission_type, :engine, :fuel_type, :colour_type, :window_type, :listing_name, :summary, :is_tv, :is_air, :is_internet, :is_sunroof, :is_bluetooth, :is_dvd, :is_gps, :is_usb, :is_audio, :is_airbags, :price, :active)
end
end