Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed use of factories, reflection on AR-Model is used. Removed fil…

…ter from index template
  • Loading branch information...
commit 3354a63cbd25c52671d6f9e200b5b5e87a8e3801 1 parent 2c79858
@aka47 authored
View
8 generators/scaffold_resource/scaffold_resource_generator.rb
@@ -16,6 +16,10 @@ class ScaffoldResourceGenerator < Rails::Generator::NamedBase
alias_method :controller_file_name, :controller_singular_name
alias_method :controller_table_name, :controller_file_name
+ def model_name
+ file_name.singularize.camelcase
+ end
+
def initialize(runtime_args, runtime_options = {})
super
@@ -46,11 +50,10 @@ def initialize(runtime_args, runtime_options = {})
else
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
end
- @attributes = Factory.attributes_for( controller_singular_name.singularize)
+ @attributes = model_name.constantize.new.attributes
end
def manifest
- @attributes = Factory.attributes_for( controller_singular_name.singularize)
record do |m|
# Check for class naming collisions.
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
@@ -109,7 +112,6 @@ def manifest
unless options[:skip_migration]
migration_template = RAILS_GEM_VERSION.to_i == 1 ? 'old_migration.rb' : 'migration.rb'
- attributes = Factory.attributes_for( controller_singular_name.singularize)
m.migration_template(
migration_template, 'db/migrate',
View
4 generators/scaffold_resource/templates/controller.rb
@@ -1,6 +1,6 @@
class <%= controller_class_name %>Controller < ResourceController::Base
def index
- @<%= controller_singular_name %> = (params[:search].present? && @collection.respond_to?(:search) ?
- <%= file_name.singularize.camelcase %>.search("%#{params[:search]}%") : <%= file_name.singularize.camelcase %>.all).paginate(:page => params[:page], :per_page => 15)
+ @<%= controller_singular_name %> = (<%= file_name.singularize.camelcase %>.respond_to?(:search) ?
+ <%= file_name.singularize.camelcase %>.search_and_filter(params[:search]) : <%= file_name.singularize.camelcase %>.all).paginate(:page => params[:page], :per_page => 15)
end
end
View
34 generators/scaffold_resource/templates/view_index.erb
@@ -1,28 +1,42 @@
+<script>
+ function filter(name, value){
+ $("#filter input#filter_by").attr("name",name).val(value);
+ $("#filter").submit()
+ }
+</script>
<div class="admin_content">
<h2><%= plural_name.titleize %></h2>
<div class="admin_actions">
<%%= link_to 'New <%= singular_name.titleize %>', new_object_url, :class=>'action_link' %>
+ <div id="admin_filter">
+ <form method="get" id="filter">
+ <%%= hidden_field_tag "sort_by_name", params[:sort_by_name] %>
+ <%%= hidden_field_tag "sort_by_direction", params[:sort_by_direction] %>
+ </form>
+ </div>
+ <br class="clear" />
+
<br class="clear" />
</div>
<table class="admin_list">
<tr class="table_head">
- <%- attributes.each do |attribute| -%>
- <th><%= attribute.first.to_s.humanize %></th>
+ <% attributes.each do |attribute| -%>
+ <th><%= attribute.first.to_s.humanize %><%%= sort_by_links("ratings_count", params); %></th>
<% end -%>
<th>&nbsp;</th>
</tr>
<%%- @<%= plural_name %>.each do |<%= singular_name %>|%>
- <tr>
+ <tr>
<%- attributes.each do |attribute| -%>
- <td><%%=h <%= singular_name %>.<%= attribute.first %> %></td>
+ <td><%%=h <%= singular_name %>.<%= attribute.first %> %></td>
<%- end -%>
- <td class="edit_links">
- <%%=link_to 'Show', object_url(<%= singular_name %>) %>
- <%%=link_to 'Edit', edit_object_url(<%= singular_name %>) %>
- <%%=link_to 'Destroy', object_url(<%= singular_name %>), :confirm => 'Are you sure?', :method => :delete %>
- </td>
- </tr>
+ <td class="edit_links">
+ <%%= link_to 'Show', object_url(<%= singular_name %>) %>
+ <%%= link_to 'Edit', edit_object_url(<%= singular_name %>) %>
+ <%%= link_to 'Destroy', object_url(<%= singular_name %>), :confirm => 'Are you sure?', :method => :delete %>
+ </td>
+ </tr>
<%% end %>
</table>
<%%= will_paginate @collection %>
Please sign in to comment.
Something went wrong with that request. Please try again.