undefined local variable or method `asistencia_params' for #<AsistenciaController:0x00000000083450>

huangapple go评论62阅读模式
英文:

undefined local variable or method `asistencia_params' for #<AsistenciaController:0x00000000083450>

问题

class AsistenciaController &lt; ApplicationController
  def asistencia
    @username = params[:user_username]
    @entry = params[:user_entry]
    if @asistencia.update(asistencia_params)
      redirect_to asistencia_path, notice: &quot;Asistencia Guardada&quot;
    else 
      render :edit, status: :unprocessable_entity
    end
  end
end

未定义局部变量或方法 `asistencia_params` 用于 #&lt;AsistenciaController:0x00000000083450&gt;

我期望能够通过名称来更新该条目

我想强调在其他控制器中,所有的用户名和条目都已经定义。
英文:
class AsistenciaController &lt; ApplicationController
  def asistencia
    @username = params[:user_username]
    @entry = params[:user_entry]
    if @asistencia.update(asistencia_params)
      redirect_to asistencia_path, notice: &quot;Asistencia Guardada&quot;
    else 
      render :edit, status: :unprocessable_entity
    end
  end
end

undefined local variable or method `asistencia_params&#39; for #&lt;AsistenciaController:0x00000000083450&gt;

I expected to be able to update the entry with the use of the name

I want to emphasize that in other controllers all the usernames, entries are already defined.

答案1

得分: 1

你需要在你的控制器中定义方法 asistencia_params,像这样:

def asistencia_params
  # 在这里你可以允许或进行其他你需要的操作
  # (例如,params 赋值或只允许处理所需的参数)
  params.require(:asistencia).permit(:user_name, :user_entry, 等等..)
end
英文:

You have to define the method asistencia_params like this in your controller.

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

huangapple
  • 本文由 发表于 2023年6月11日 21:36:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76450722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定