Skip to content

Commit

Permalink
Ensure that there is always a 'name' field of SOME type.
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Feb 29, 2012
1 parent c1622a5 commit 363edb5
Showing 1 changed file with 24 additions and 13 deletions.
@@ -1,26 +1,37 @@
module Refinery
module <%= class_name.pluralize %>
class <%= class_name %> < Refinery::Core::BaseModel
<% if table_name == namespacing.underscore.pluralize -%>self.table_name = :refinery_<%= plural_name %><% end -%>
acts_as_indexed :fields => [:<%= (string_fields = attributes.collect{ |a| a.name if a.type.to_s =~ /string|text/ }.compact.uniq).join(", :") %>]

# Add some validation here if you want to validate the user's input<% if string_fields.any? %>
<% if table_name == namespacing.underscore.pluralize -%>
self.table_name = :refinery_<%= plural_name %>
<% end -%>
<% if (string_fields = attributes.map{ |a| a.name if a.type.to_s =~ /string|text/ }.compact.uniq).any? %>
acts_as_indexed :fields => [:<%= string_fields.join(", :") %>]
<% end -%>
<% unless string_fields.detect{|f| f.to_s == 'name'} %>
alias_attribute :name, :<%= string_fields.first %>
<% end %>
# Add some validation here if you want to validate the user's input
<% if string_fields.any? -%>
# We have validated the first string field for you.
validates :<%= string_fields.first %>, :presence => true
<% end -%>
<% attributes.select{|a| a.type.to_s == 'image'}.uniq.each do |a| -%>
<% else %>
# def name was created automatically because you didn't specify a string field
# when you ran the refinery:form generator. <3 <3 Refinery CMS.
def name
"Override def name in vendor/extensions/<%= namespacing %>/app/models/refinery/<%= namespacing %>/<%= singular_name %>.rb"
end
<% end -%>
<% attributes.select{|a| a.type.to_s == 'image'}.uniq.each do |a| -%>
belongs_to :<%= a.name.gsub("_id", "") -%>, :class_name => '::Refinery::Image'
<% end -%>
<% attributes.select{|a| a.type.to_s == 'resource'}.uniq.each do |a| -%>
<% end -%>
<% attributes.select{|a| a.type.to_s == 'resource'}.uniq.each do |a| -%>
belongs_to :<%= a.name.gsub("_id", "") %>, :class_name => '::Refinery::Resource'
<% end -%>
<% attributes.select{|a| a.type.to_s =~ /radio|select/}.uniq.each do |a| %>
<% end -%>
<% attributes.select{|a| a.type.to_s =~ /radio|select/}.uniq.each do |a| -%>
<%= a.name.pluralize.upcase %> = []
<% end %>
<% end -%>
end
end
end

0 comments on commit 363edb5

Please sign in to comment.