Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding attr_accessible functionality

  • Loading branch information...
commit ef22881ef733d66cd3e334e7db47c47f98441dad 1 parent 3604a98
Mike Gunderloy ffmike authored
8 generators/model_plus/model_plus_generator.rb
View
@@ -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
2  generators/model_plus/templates/migration.rb
View
@@ -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] %>
7 generators/model_plus/templates/model.rb
View
@@ -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
2  website
@@ -1 +1 @@
-Subproject commit 3b535e2e736d6bfcc4e2bd5f15f6218c18ae2c52
+Subproject commit 73ea9b1581ca5bcbc6062164ba05b165ed9ed1ae
Please sign in to comment.
Something went wrong with that request. Please try again.