From 3c282717ccdcced2447747edee6941e80cc4cec0 Mon Sep 17 00:00:00 2001 From: Iain Hecker Date: Fri, 17 Jul 2009 12:15:45 +0200 Subject: [PATCH] Some more refactoring --- app/controllers/root_table/manage_controller.rb | 5 ++++- app/controllers/root_table/tables_controller.rb | 10 +--------- app/views/root_table/manage/edit.html.haml | 2 +- app/views/root_table/manage/new.html.haml | 2 +- lib/root_table.rb | 8 +++++++- locale.yml | 12 +++++++----- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/controllers/root_table/manage_controller.rb b/app/controllers/root_table/manage_controller.rb index 1acc37a..673390a 100644 --- a/app/controllers/root_table/manage_controller.rb +++ b/app/controllers/root_table/manage_controller.rb @@ -67,7 +67,10 @@ def model helper_method :model def columns - @columns ||= model.column_names - %w[ id updated_at created_at ] + return @columns if @columns + @columns = model.column_names - %w[ id updated_at created_at ] + @columns -= [ root_table.order.to_s ] if root_table.acts_as_list? + @columns end helper_method :columns diff --git a/app/controllers/root_table/tables_controller.rb b/app/controllers/root_table/tables_controller.rb index bdd763f..b60d075 100644 --- a/app/controllers/root_table/tables_controller.rb +++ b/app/controllers/root_table/tables_controller.rb @@ -1,15 +1,7 @@ class RootTable::TablesController < ApplicationController - before_filter :find_root_tables - def index - end - - private - - def find_root_tables - Dir.glob(File.join(Rails.root, "app", "models", "**" "*.rb")).each { |f| require f } - @tables = ActiveRecord::Base.root_tables || {} + @tables = ActiveRecord::Base.all_root_tables end end diff --git a/app/views/root_table/manage/edit.html.haml b/app/views/root_table/manage/edit.html.haml index a7dc56a..09adcf7 100644 --- a/app/views/root_table/manage/edit.html.haml +++ b/app/views/root_table/manage/edit.html.haml @@ -1,4 +1,4 @@ -%h2= "Edit " + model.human_name +%h2= rt(:edit_header, :table => model.human_name) - form_for @object, :url => root_table_table_manage_path(table) do |f| = render :partial => "form", :locals => { :f => f } diff --git a/app/views/root_table/manage/new.html.haml b/app/views/root_table/manage/new.html.haml index 2151abc..01527a0 100644 --- a/app/views/root_table/manage/new.html.haml +++ b/app/views/root_table/manage/new.html.haml @@ -1,4 +1,4 @@ -%h2= "New " + model.human_name +%h2= rt(:new_header, :table => model.human_name) - form_for @object, :url => root_table_table_manage_index_path(table) do |f| = render :partial => "form", :locals => { :f => f } diff --git a/lib/root_table.rb b/lib/root_table.rb index 07f77a7..9770d71 100644 --- a/lib/root_table.rb +++ b/lib/root_table.rb @@ -43,6 +43,13 @@ def root_table_for(target_name, options = {}) ::ActiveRecord::Base.root_tables[root_table.source_name] << root_table end + # Returns all root tables found (in the app/models directory). + # Used in the controller to build up a list for that. + def all_root_tables + Dir.glob(File.join(Rails.root, "app", "models", "**" "*.rb")).each { |f| require f } + ::ActiveRecord::Base.root_tables || {} + end + class RootTable attr_reader :target_name, :options, :source @@ -122,7 +129,6 @@ def opt?(option) !options.has_key?(option) || !options[option] end - end end diff --git a/locale.yml b/locale.yml index 05c1c5a..27c2af6 100644 --- a/locale.yml +++ b/locale.yml @@ -1,17 +1,19 @@ en: root_table: - table_header: Select a root table to manage - used_by: Used by {{tables}} + table_header: "Select a root table to manage" + used_by: "Used by {{tables}}" used_as: " (as '{{to}}')" - manage_header: Manage {{table}} + manage_header: "Manage {{table}}" + new_header: "New {{table}}" + edit_header: "Edit {{table}}" handle: "[DRAG]" created: "Successfully created {{table}}" updated: "Successfully updated {{table}}" destroyed: "Successfully deleted {{table}}" new: "New {{table}}" - edit: "edit" - delete: "delete" + edit: "Edit" + delete: "Delete" back: "Back" actions: "Actions" confirm: "Are you sure you want to delete this?"