>当我发送我收到的表单数据时:
NoMethodError (未定义的方法"permit"为"create":String(:
app/controllers/actions_controller.rb:53:inaction_params'
app/controllers/actions_controller.rb:18:in
create'
这是形式:
= controlled_form do
= render 'shared/error_messages', object: @action
= remote_form(@action, html: { id: "actionsForm" }) do |f|
= input_group "fas fa-file-alt" do
= f.text_field :name,
autofocus: true,
placeholder: t('actions.form.name'),
class: "form-control"
= input_group 'fas fa-file-alt' do
= f.text_area :description,
placeholder: t('actions.form.description'),
class: "form-control"
以及创建的功能:
def create
@action = Action.new(action_params)
if @action.save
flash[:success] = ""#{@action.name}" was created"
respond_to do |format|
format.js { render js: "Turbolinks.visit('#{actions_path}')" }
end
else
render_form status: :bad_request
end
end
最后:
def action_params
params.require(:action).permit(:name, :description)
end
"action" 是参数哈希上引用当前控制器操作的特殊键,您不应将action
用作参数表。我不确定您为表单使用什么(remote_form
不是常见的 rails 表单帮助程序方法(,但它应该为您提供一个更改的选项,例如form_with
助手 https://apidock.com/rails/ActionView/Helpers/FormHelper/form_with 上的scope
选项
将其更改为"action_object"或"操作"以外的任何内容,然后在action_params
处执行相同的更改。