Check_box_tag不会在rails app中保留值

我有一个名为“客户”的模型。 客户端模型属于用户模型(用户模型与设计相关联)。 还有另一种称为“卖家”的模型,但他们没有涉及这个问题。 客户可以手动向我付款(仅限现金)。 当客户付款时,我会让他们访问网站上的更多页面。 为此,我向客户添加了一个名为“付费”的布尔变量,然后管理员(我)可以转到他们的客户档案,通过复选框将付费状态从“未付”更新为“付费”。 只有管​​理员才能查看该复选框。

这是更新客户信息的部分forms:

          

然后我的客户端控制器是:

 class ClientController < ApplicationController before_action :find_client, only: [:show, :edit, :update, :destroy] def index end def show end def new @client = current_user.build_client end def create @client = current_user.build_client(client_params) if @client.save redirect_to clients_path else render 'new' end end def edit end def update end def destroy @client.destroy redirect_to root_path end private def client_params if current_user.user_type == :admin params[:client][:paid] = params[:client][:paid] == 'yes' params.require(:client).permit(:paid, :name, :company, :position, :number, :email, :client_img) else params.require(:client).permit(:name, :company, :position, :number, :email, :client_img) end end def find_client @client = Client.find(params[:id]) end end 

当我转到客户端配置文件,然后单击“更新”信息时,我得到部分表单,其中,未选中复选框。 我点击它并更新配置文件,没有错误,带我回到配置文件。 但是,当我再次单击“更新”时,将取消选中该复选框。 它不会仅保留复选框的值。 其他一切都保留了下来。 喜欢这个名字,公司和所有这些。 当我进入rails c时,即使我点击它并更新它,付费变量仍然是假的。 有谁知道为什么会如此? 请不要downvote,我是新来的。 请告诉我在没有低估的情况下需要改变的地方。

使用check_box表单助手代替check_box_tag到表单中,并从client_params方法中删除行:

 params[:client][:paid] = params[:client][:paid] == 'yes'