Customizing Active Scaffold according to your requirements is very easy.
Example :- Removing create, edit or delete links from your page and add your own links
Also add nested links if this model is related to other model. Example there is another model name as Product which is related to Category model say category has many products and product belongs to Category.
For that we need to do the following
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, :products]
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
#this is a extra link which is applicable for every row if type record and if type is table then it is for all records
config.action_links.add "cat",:label=>"Categories",:type=>:record
#this is a link to products where you can list add edit delete and associate products to category
config.nested.add_link "Add Products", [:products]
end
def cat
#your required code
end
Considering product model we have fields like product_name, product_description, category_id
active_scaffold :product do |config|
config.label = "Product Page" # Display page name
# Category_id not needed by default it will take while adding
config.columns = [:product_name, :product_description]
config.columns[:product_name].label = "Product Name"
list.columns.exclude :product_description
end
and we need to add the required code in Product_Helper.rb as we did in category_helper.rb
and also we can add our own code if required during update and create by copying the code from …\vendor\plugins\active_scaffold\lib\actions to your controller and edit it as required
Now in your page you can add and associate products to category.
No comments:
Post a Comment