Acivescaffold is a plugin which makes the life easier for many programmers. Assuming that you have downloaded and installed the plugin. We proceed with an example.
Consider there is a model named as “category” with fields like name, rank and description and we are now integrating this with Activescaffold
Now in controller we need to write the following code:
active_scaffold :category do |config|
config.label = "Category" # Display page name
config.columns = [:name, :rank, :description] # all fields are taken
config.columns[:name].label = "Some Name" # customize column name
update.columns.exclude :rank # exclude rank column during edit
list.columns.exclude :description #exclude description column in list
end
Now in Category_helper.rb we need to write the following code to display the field format Ex:- Textbox, Dropdown , checkbox etc.
# Textbox to enter name
def name_form_column(record,input_name)
textbox :record, :name, :name=> input_name
end
# Label to display name
def name_column(record)
record.name
end
# Textarea to enter the description
def description_form_column(record,input_name)
textarea :record, :name, :name=> input_name
end
# Label to display description
def description_column(record)
record.description
end
# Dropdown to select rank
def rank_form_column(record,input_name)
select(:record,:pricing,[1,2,3,4,5,6,7,8,9,10],:name=> input_name)
end
# Label to display rank
def rank_column(record)
record.rank
end
That’s it your code will work fine. No rhtml code is required.
No comments:
Post a Comment