我有"付款"字段显示为标记,我的数据库中的布尔类型,如果可能,我想在此字段上添加操作。如果我点击这个字段,我希望将状态从false更改为true,然后反转。这一切都在索引列表中。
ActiveAdmin.register Booking do
permit_params :user_id, :race_id, :payment
actions :all
index do
selectable_column
column :race
column :user
column :payment
column :created_at
column :updated_at
actions
end
end
答案 0 :(得分:1)
档案routes.rb
//config/routes.rb
scope :admin do
resources :bookings do
member do
get :payment
end
end
end
我的文件booking.rb
//app/admin/booking.rb
ActiveAdmin.register Booking do
permit_params :user_id, :race_id, :payment
actions :all
controller do
def payment
booking = Booking.find(params[:id])
booking.payment = !booking.payment # toggle the status
booking.save
redirect_to booking_path(booking)
end
end
index do
selectable_column
column :race
column :user
column "Confirm" do |booking|
link_to "Confirm", payment_booking_path(booking)
end
column :created_at
column :updated_at
actions
end
end
我的代码出了什么问题,因为我得到了“未初始化的常量BookingsController”。我的链接:admin / bookings / 16 / payment
答案 1 :(得分:0)
在视图中
= link_to (@booking.payment ? true : false), payment_booking_path(@booking)
控制器中的
def payment
booking = Booking.find(params[:id])
booking.payment = !booking.payment # toggle the status
booking.save
redirect_to booking_path(booking)
end
在路线
resources :bookings do
member do
get :payment
end
end