Active Scaffold : Add checkbox array for a particular field in rails?
Suppose you have a field in your table, which accepts array of values through multiple checkboxes, then here is a way to show these checkboxes on your active scaffold create/update form.
#Controller
class UsersController < ApplicationController
active_scaffold :user do |config|
config.label = “Users”
config.columns = [:name, :gender, :checklist ]
config.columns[:gender].form_ui = :radio
config.columns[:gender].options[:options] = [['Male', '1'], ['Female','2']]
end
end
Assume ‘checklist’ is the column which accepts an array of values, then add the below chunk of code to your users helper
#Users helper
module UsersHelper
def checklist_form_column(record, options)
html = ‘ ‘
(1..5).each do |val|
html << check_box_tag(“record[checklist][]“, val, :id => “check_#{val}”)
html << “<label for=’check_#{val}’>”
html << “lable_#{val}”
html << “</label>”
html << “<br/>”
end
html
end
end
Suppose you have a field in your table, which accepts array of values through multiple checkboxes, then here is a way to show these checkboxes on your active scaffold create/update form.
#Controller
class UsersController < ApplicationController
active_scaffold :user do |config|
config.label = “Users”
config.columns = [:name, :gender, :checklist ]
config.columns[:gender].form_ui = :radio
config.columns[:gender].options[:options] = [['Male', '1'], ['Female','2']]
end
end
Assume ‘checklist’ is the column which accepts an array of values, then add the below chunk of code to your users helper
#Users helper
module UsersHelper
def checklist_form_column(record, options)
html = ‘ ‘
(1..5).each do |val|
html << check_box_tag(“record[checklist][]“, val, :id => “check_#{val}”)
html << “<label for=’check_#{val}’>”
html << “lable_#{val}”
html << “</label>”
html << “<br/>”
end
html
end
end
Comments
Post a Comment