Overriding input components in active scaffold
One of the wonderful facts about Rails is that most stuff you need is already created for you, keeping you free to customize as you want.
ActiveScaffold is one of the most powerful and widely used plugins in rails projects because it simply provide you with a complete CRUD for your model with minimum coding.
The default view of the active scaffold is adequate for some applications, but not the most pretty. so is the input types used for the model attributes. Active Scaffold team helps us by providing and easy way to customize by overriding active scaffold defaults.
In my application i had a boolean attribute "admin" in my model "user". that was showed as a drop down list having the values of true & false. Pretty ugly.
I used partial form overrides to make it the more logical check box by adding
app/views/users/_admin_form_column.rhtml
with the following content:
Now when i create a new user, i can see a check box at the admin field. instead of the old ugly dropdown list.
ActiveScaffold is one of the most powerful and widely used plugins in rails projects because it simply provide you with a complete CRUD for your model with minimum coding.
The default view of the active scaffold is adequate for some applications, but not the most pretty. so is the input types used for the model attributes. Active Scaffold team helps us by providing and easy way to customize by overriding active scaffold defaults.
In my application i had a boolean attribute "admin" in my model "user". that was showed as a drop down list having the values of true & false. Pretty ugly.
I used partial form overrides to make it the more logical check box by adding
app/views/users/_admin_form_column.rhtml
with the following content:
< dl >
< dt >
< label >is admin ?< /label >
< /dt >
< dd >
<%=check_box :record, :admin, :name => 'record[admin]'%>
< /dd >
< /dl >
Now when i create a new user, i can see a check box at the admin field. instead of the old ugly dropdown list.
Comments