ActiveAdmin在控制器中传递变量 [英] ActiveAdmin passing variable in controller

查看:58
本文介绍了ActiveAdmin在控制器中传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许可证和车辆型号。我正在尝试更新AA创建控制器,以使其在Rails应用程序中运行。也就是说,将输入的车辆license_number输入并将其输入到许可表中,然后还将输入的permit_id输入并将其输入到与该车辆表相关的车辆的permits属性中。

I have a permit and vehicle model. I am trying to update the AA create controller to work how I have it in my rails app. That is taking the vehicle license_number entered and inputting it into the permit table, then also taking the inputted permit_id and inputting it into the permits attribute of the vehicle it is related to in the vehicle table.

admin / permit.rb

permit_params :permit_id, :vehicle, :date_issued, :issued_by, :date_entered, :entered_by

form do |f|
    f.inputs do
        f.input :permit_id
        f.input :vehicle, :collection => Vehicle.all.map{ |vehicle| [vehicle.license_number]}
        f.input :date_issued, as: :date_picker
        f.input :issued_by
    end
    f.actions
end

controller do
    def new
        @permit = Permit.new
        @vehicle = @permit.build_vehicle
        @vehicle = Vehicle.all 
        super
    end 

    def create
         vehicle = Vehicle.find_by(license_number: permit_params[:vehicle_attributes][:license_number])
         @permit = current_user.permit.build(permit_params.merge(date_entered: Date.today, 
            entered_by: current_user_admin.email))
         super
    end
end

我得到的错误是,它在输入allow_id的license_number,然后又说allow_params不是定义的变量。

My errors that I am getting, is that it is inputting the license_number in for the permit_id and then it is also saying the permit_params is not a defined variable. Any help would be great, thanks!

推荐答案

我会避免使用Permit作为模型名称,请尝试使用VehiclePermit。

I would avoid Permit as a model name, try using VehiclePermit.

这篇关于ActiveAdmin在控制器中传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆