aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/named_base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/generators/named_base.rb')
-rw-r--r--railties/lib/rails/generators/named_base.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 01a8e2e9b4..efbf51ddfb 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -18,8 +18,8 @@ module Rails
parse_attributes! if respond_to?(:attributes)
end
- # Defines the template that would be used for the migration file.
- # The arguments include the source template file, the migration filename etc.
+ # Overrides <tt>Thor::Actions#template</tt> so it can tell if
+ # a template is currently being created.
no_tasks do
def template(source, *args, &block)
inside_template do
@@ -129,6 +129,18 @@ module Rails
uncountable? ? "#{plural_table_name}_index" : plural_table_name
end
+ def show_helper
+ "#{singular_table_name}_url(@#{singular_table_name})"
+ end
+
+ def edit_helper
+ "edit_#{show_helper}"
+ end
+
+ def new_helper
+ "new_#{singular_table_name}_url"
+ end
+
def singular_table_name
@singular_table_name ||= (pluralize_table_names? ? table_name.singularize : table_name)
end
@@ -149,6 +161,10 @@ module Rails
@route_url ||= class_path.collect {|dname| "/" + dname }.join + "/" + plural_file_name
end
+ def url_helper_prefix
+ @url_helper_prefix ||= (class_path + [file_name]).join('_')
+ end
+
# Tries to retrieve the application name or simply return application.
def application_name
if defined?(Rails) && Rails.application
@@ -183,6 +199,10 @@ module Rails
!defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names
end
+ def mountable_engine?
+ defined?(ENGINE_ROOT) && namespaced?
+ end
+
# Add a class collisions name to be checked on class initialization. You
# can supply a hash with a :prefix or :suffix to be tested.
#