Fri 16 Nov 2007
Adding icons to ActiveScaffold’s actions
Posted by kosmas under ruby on rails
Problem
You want to replace the standard text descriptions in ActiveScaffold’s actions with your icons.
Solution
- Create a file called active_scaffold_overrides.css in ror_project/public/stylesheets
- Copy the css code from ror_project/vendor/plugins/active_scaffold/frontends/default/stylesheets/stylesheet.css and paste it in to the file created in the previous step.
- Create a directory my_images in ror_project/public/images/activescaffold to hold your images.
- Copy to the new directory the images you want to use in the application.
- In the active_scaffold_overrides.css file find the section named:
/* Table :: Actions (Edit,Delete) .... */
and for each action that you want to use an icon add (ie edit)
.active_scaffold tr.record td.actions a.edit { display: block; width: 16px; height: 16px; background: transparent url(../../../images/active_scaffold/my_images/image.png) no-repeat right 50%; } - In the application.rb, if you want the links to be the same for the whole application add:
ActiveScaffold.set_defaults do |config| config.update.link.label ="" end - in your layout/application.rhtml (create one if you don’t already have one), include
<%= stylesheet_link_tag "active_scaffold_overrides" %>
- Restart webrick/mongrel
2 Responses to “ Adding icons to ActiveScaffold’s actions ”
Comments:
Leave a Reply
You must be logged in to post a comment.
April 26th, 2008 at 9:22 pm
Thanks for the article. Playing with this led me to another solution. I simply set the link label to be an image tag.
ActiveScaffold.set_defaults do |conf|
conf.update.link.label = ''
end
April 26th, 2008 at 9:26 pm
OK. The HTML was stripped from my reply.
Fill in the lt and gt signs:
ActiveScaffold.set_defaults do |conf|
conf.update.link.label = ‘img src=”path/to/edit.gif” border=0′
end