Контроллер:
class CuratorController < ApplicationController
def index
@studs = Stud.all
end
def show
@stud = Stud.find(params[:id])
end
def new
@studs = Stud.new
end
def create
@stud = Stud.new(stud_params)
@stud.save
redirect_to new_curators_path
end
private
def stud_params
params.permit(:fio, :test)
end
end
Страница на которой пользователь вводит данные:
<h1>New Student</h1>
<%= form_with model: @stud do |form| %>
<div>
<%= form.label :text %><br>
<%= form.text_field :fio %>
</div>
<div>
<%= form.label :integer %><br>
<%= form.text_field :test %>
</div>
<div>
<%= form.submit type: "submit", name:"action" %>
</div>
<% end %>
Пишет, что param отсутствует или значение пустое: stud Не могу понять почему, в консоли, где запущен сервер вот это:
ActionController::ParameterMissing (param is missing or the value is empty: stud):
app/controllers/curator_controller.rb:25:in `stud_params'
app/controllers/curator_controller.rb:15:in `create'
Started POST "/curator" for ::1 at 2023-01-09 02:45:58 +0300
Processing by CuratorController#create as HTML
Parameters: {"authenticity_token"=>"[FILTERED]", "text"=>"Аметист", "integer"=>"76"}
Completed 400 Bad Request in 4ms (Allocations: 1476)
ActionController::ParameterMissing (param is missing or the value is empty: stud):
app/controllers/curator_controller.rb:23:in `stud_params'
app/controllers/curator_controller.rb:15:in `create'
Добавил код routes. Почему-то resources не создаёт сам Post, поэтому написал его отдельно, вот код
Rails.application.routes.draw do
root "curator#index"
resources :curator
post 'curator/new', to: 'curator#create'
end
Обновил код контроллера и страницы html Сейчас ругается на stud.save выдаёт: undefined method `integer' for #<Stud id: nil, fio: "Ametist", test: 12412412, created_at: nil, updated_at: nil> Когда ввожу соответственно Ametist и 12412412 P.S. Спасибо большое за то, что уже видит данные, которые вводит, это очень большой прогресс для меня!