hzamani / acts_as_relation

Multi table Inheritance for rails
http://hzamani.github.com/acts_as_relation/
MIT License
180 stars 58 forks source link

Undefined local variable on rails-3.2.3 #16

Closed miscelatore closed 12 years ago

miscelatore commented 12 years ago

Hello,

I.m try to use your gem by following the read me.

class Product < ActiveRecord::Base attr_accessible :name, :price

acts_as_superclass

validates_presence_of :name, :price

def hello puts "Hello, My name is '#{name}', my price is $#{price}." end end

class Pen < ActiveRecord::Base attr_accessible :color

acts_as :product, :as => :as_product end

rails console

p = Pen.new NameError: undefined local variable or method includeconditionsautosavetrueclass_nameProductasas_productdependentdestroyvalidatefalse' for ActiveRecord::ActsAsModules::ActsAsProduct:Module from /Library/Ruby/Gems/1.8/gems/acts_as_relation-0.1.1/lib/active_record/acts_as_relation.rb:93:inincluded' from /Library/Ruby/Gems/1.8/gems/acts_as_relation-0.1.1/lib/active_record/acts_as_relation.rb:96:in include' from /Library/Ruby/Gems/1.8/gems/acts_as_relation-0.1.1/lib/active_record/acts_as_relation.rb:96:inacts_as' from /Library/Ruby/Gems/1.8/gems/acts_as_relation-0.1.1/lib/active_record/acts_as_relation.rb:95:in class_eval' from /Library/Ruby/Gems/1.8/gems/acts_as_relation-0.1.1/lib/active_record/acts_as_relation.rb:95:inacts_as' from /Users/stefano/RoR/test_acts_as_relation/app/models/pen.rb:4 from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:469:in load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:469:inload_file' from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:639:in new_constants_in' from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:468:inload_file' from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:353:in require_or_load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:inload_missing_constant' from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in const_missing' from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:ineach' from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `const_missing' from (irb):1

Have you any idea?

Best regards

ss

hzamani commented 12 years ago

Can you test it with ruby 1.9?

miscelatore commented 12 years ago

No til this moment

ss

Il giorno 17/mag/2012, alle ore 17:09, Hassan Zamanireply@reply.github.com ha scritto:

Can you test it with ruby 1.9?


Reply to this email directly or view it on GitHub: https://github.com/hzamani/acts_as_relation/issues/16#issuecomment-5765938

miscelatore commented 12 years ago

I do not have a machine with ruby​​-1.9

hzamani commented 12 years ago

This is a ruby 1.9 specific gem (not compatible with 1.8). If you want to install 1.9 there is a Ruby Version Manager.

miscelatore commented 12 years ago

I have ruby 1.9.3 installed on my computer. Now I get the following error when creating a new record:

$ rails console Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > pen = Pen.new(:name=>"Red Pen", :color=>:red, :price=>0.99) ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: name, price from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:48:in process_removed_attributes' from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:20:indebug_protected_attribute_removal' from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:12:in sanitize' from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security.rb:230:insanitize_for_mass_assignment' from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/attribute_assignment.rb:75:in assign_attributes' from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/base.rb:498:ininitialize' from (irb):1:in new' from (irb):1 from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:47:instart' from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in start' from /Users/stefano/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:41:in<top (required)>' from script/rails:6:in require' from script/rails:6:in

'

Have you any idea?

Best regards

ss

miscelatore commented 12 years ago

I solved it by changing the model pen like this:

class Pen <ActiveRecord :: Base attr_accessible: color,: name,: price

acts_as: product,: as =>: producible end

bye

ss

hzamani commented 12 years ago

Yes, in rails 3.2 attr_accessibles are required. I will add in in docs, tanks.