Я пытаюсь сохранить данные формы в базу данных, но вместо этого нулевые значения вводятся, что может быть проблемой? мой взгляд form.html.erb файлрельсы формируют данные, которые не сохраняются в базе данных
<%= form_for(@cattle_client) do |f| %>
<% if @cattle_client.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@cattle_client.errors.count, "error") %> prohibited this cattle_client from being saved:</h2>
<ul>
<% @cattle_client.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :client_name %><br>
<%= f.text_field :client_name %>
</div>
<div class="field">
<%= f.label :milk %><br>
<%= f.number_field :milk %>
</div>
<div class="field">
<%= f.label :date %><br>
<%= f.date_select :date %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Мой cattle_clients_controller.rb является
class CattleClientsController < ApplicationController
before_action :set_cattle_client, only: [:show, :edit, :update, :destroy]
# GET /cattle_clients
# GET /cattle_clients.json
def index
@cattle_clients = CattleClient.all
end
# GET /cattle_clients/1
# GET /cattle_clients/1.json
def show
end
# GET /cattle_clients/new
def new
@cattle_client = CattleClient.new
end
# GET /cattle_clients/1/edit
def edit
end
# POST /cattle_clients
# POST /cattle_clients.json
def create
@cattle_client = CattleClient.new(cattle_client_params)
respond_to do |format|
if @cattle_client.save
format.html { redirect_to @cattle_client, notice: 'Cattle client was successfully created.' }
format.json { render :show, status: :created, location: @cattle_client }
else
format.html { render :new }
format.json { render json: @cattle_client.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /cattle_clients/1
# PATCH/PUT /cattle_clients/1.json
def update
respond_to do |format|
if @cattle_client.update(cattle_client_params)
format.html { redirect_to @cattle_client, notice: 'Cattle client was successfully updated.' }
format.json { render :show, status: :ok, location: @cattle_client }
else
format.html { render :edit }
format.json { render json: @cattle_client.errors, status: :unprocessable_entity }
end
end
end
# DELETE /cattle_clients/1
# DELETE /cattle_clients/1.json
def destroy
@cattle_client.destroy
respond_to do |format|
format.html { redirect_to cattle_clients_url, notice: 'Cattle client was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_cattle_client
@cattle_client = CattleClient.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def cattle_client_params
params.require(:cattle_client).permit(:client_name, :milk, :date)
end
end
И мой файл имеет маршруты
resources :cattle_clients
Любой помочь мне определить, в чем проблема?
Мой Миграции файл
class CreateCattleClients < ActiveRecord::Migration
def change
create_table :cattle_clients do |t|
t.string :client_name
t.integer :milk
t.date :date
t.timestamps null: false
end
end
end
модель
class CattleClient < ActiveRecord::Base
end
Опубликуйте свой полный файл контроллера. –
Кроме того, ваш журнал рельсов s также записывается при сохранении. – membLoper
Почему в контроллере есть какие-то ошибки? 0_o В любом случае, есть ли у вас какие-либо ошибки в вашей модели? – BroiSatse