Ajaxscaffold table title fix
From SubfireWiki
I couldn't see a way to allow for different table titles when using ajaxscaffold so I created this patch.
Contents |
Usage
In order to use the fix, all that is needed is to set the table_title when calling the ajax_scaffold method.
ajax_scaffold :deployment, :table_title => "My Title"
The Fixes
app/views/ajax_scaffold/table.rhtml
Use the new scaffold_table_title variable:
<h2><%= @scaffold_table_title.titleize %></h2>
app/lib/ajax_scaffold_plugin.rb
- Added the option :table_title:
options.assert_valid_keys(:class_name, :except, :rows_per_page, :suffix, :totals, :width, :rel_width, :table_title)
- Set a local var - table_title to the new option or the plural_name if the :table_title is not set:
table_title = options[:table_title] || plural_name
- In the render#{suffix}_template( options = {} ) method, setup a new "view variable"
@scaffold_table_title = "#{table_title}"
The Patch File
Index: app/views/ajax_scaffold/table.rhtml
===================================================================
--- app/views/ajax_scaffold/table.rhtml (revision 88)
+++ app/views/ajax_scaffold/table.rhtml (working copy)
@@ -21,7 +21,7 @@
{ :href => url_for(new_params), :class => "create" } %>
</div>
<% end %>
- <h2><%= @scaffold_plural_name.titleize %></h2>
+ <h2><%= @scaffold_table_title.titleize %></h2>
</div>
<table cellpadding="0" cellspacing="0">
<thead>
@@ -60,4 +60,4 @@
<script type="text/javascript">
Rico.Corner.round('<%= params[:scaffold_id] %>', {color: '#005CB8', bgColor: '#fff', compact: true});
</script>
-<% end %>
\ No newline at end of file
+<% end %>
Index: lib/ajax_scaffold_plugin.rb
===================================================================
--- lib/ajax_scaffold_plugin.rb (revision 88)
+++ lib/ajax_scaffold_plugin.rb (working copy)
@@ -125,7 +125,8 @@
# Adds a swath of actions to the controller.
def ajax_scaffold(model_id, options = {})
- options.assert_valid_keys(:class_name, :except, :rows_per_page, :suffix, :totals, :width, :rel_width)
+ # MTM - table title fix added :table_title (malcomm [at] gmail [dot] com)
+ options.assert_valid_keys(:class_name, :except, :rows_per_page, :suffix, :totals, :width, :rel_width, :table_title)
# set up a few variables for use in the code generation
singular_name = model_id.to_s
@@ -136,6 +137,8 @@
prefix = options[:suffix] ? "#{plural_name}_" : ""
totals = options[:totals].nil? ? nil : options[:totals].join(',').to_s
width = options[:width].nil? ? (options[:rel_width].nil? ? nil : options[:rel_width]*100 ) : options[:width]
+ # MTM - if the :table_title option is sent in then use use (malcomm [at] gmail [dot] com)
+ table_title = options[:table_title] || plural_name
if (!width.nil?)
dimensions = options[:width].nil? ? "%" : "px"
@@ -412,6 +415,8 @@
@no_delete = #{no_delete}
@suffix = "#{suffix}"
@prefix = "#{prefix}"
+ # MTM new view var (malcomm [at] gmail [dot] com)
+ @scaffold_table_title = "#{table_title}"
# check for template in following order:
# views/scaffold_class/template
@@ -513,4 +518,4 @@
end
end
end
-end
\ No newline at end of file
+end
