提问人:Edrei Beltrán 提问时间:6/11/2023 更新时间:6/12/2023 访问量:40
#<AsistenciaController:0x00000000083450> 的未定义局部变量或方法“asistencia_params”
undefined local variable or method `asistencia_params' for #<AsistenciaController:0x00000000083450>
问:
class AsistenciaController < ApplicationController
def asistencia
@username = params[:user_username]
@entry = params[:user_entry]
if @asistencia.update(asistencia_params)
redirect_to asistencia_path, notice: "Asistencia Guardada"
else
render :edit, status: :unprocessable_entity
end
end
end
undefined local variable or method `asistencia_params' for #<AsistenciaController:0x00000000083450>
我希望能够使用名称更新条目
我想强调的是,在其他控制器中,所有用户名、条目都已定义。
答:
1赞
jansha
6/12/2023
#1
您必须在控制器中定义方法asistencia_params如下所示。
def asistencia_params
#here you can permit or do whatever you want
(eg params assignment or permiting only required params for processing)
params.require(:asistencia).permit(:user_name, :user_entry, etc..)
end
评论
asistencia_params
private
def user_params
bundle exec rails g scaffold Post title:string body:string
posts_controller.rb
#post_params
params.require(:post).permit(:title, :body)