Skip to content

Commit

Permalink
Some more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
iain committed Jul 17, 2009
1 parent a0663df commit 3c28271
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
5 changes: 4 additions & 1 deletion app/controllers/root_table/manage_controller.rb
Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions 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
2 changes: 1 addition & 1 deletion 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 }
2 changes: 1 addition & 1 deletion 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 }
8 changes: 7 additions & 1 deletion lib/root_table.rb
Expand Up @@ -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
Expand Down Expand Up @@ -122,7 +129,6 @@ def opt?(option)
!options.has_key?(option) || !options[option]
end


end

end
Expand Down
12 changes: 7 additions & 5 deletions 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?"

0 comments on commit 3c28271

Please sign in to comment.