Permalink
Browse files

Adding attr_accessible functionality

  • Loading branch information...
1 parent 3604a98 commit ef22881ef733d66cd3e334e7db47c47f98441dad @ffmike ffmike committed Dec 21, 2008
@@ -6,6 +6,14 @@ def referenced_by?
[ :has_one, :has_many, :has_and_belongs_to_many ].include?(self.type)
end
+ def base_type
+ self.type.to_s.split('+')[0]
+ end
+
+ def type_attributes
+ self.type.to_s.split('+')[1]
+ end
+
end
end
end
@@ -3,7 +3,7 @@ def self.up
create_table :<%= table_name %> do |t|
<% for attribute in attributes -%>
<% unless attribute.referenced_by? %>
- t.<%= attribute.type %> :<%= attribute.name %>
+ t.<%= attribute.base_type %> :<%= attribute.name %>
<% end -%>
<% end -%>
<% unless options[:skip_timestamps] %>
@@ -5,4 +5,11 @@ class <%= class_name %> < ActiveRecord::Base
<% attributes.select(&:referenced_by?).each do |attribute| -%>
<%= attribute.type %> :<%= attribute.name %>
<% end -%>
+<% attr_accessible = [] %>
+<% attributes.each do |attribute| -%>
+ <% attr_accessible << ":" + attribute.name if attribute.type_attributes =~ /a/ -%>
+<% end -%>
+<% if !attr_accessible.empty? -%>
+ attr_accessible <%= attr_accessible.join(", ") %>
+<% end -%>
end

0 comments on commit ef22881

Please sign in to comment.