I have this in a model: has_one :next, :class_name=>''WorkPart'', :foreign_key=>''next_id'' And it causes this error: compile error /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/deprecated_associations.rb:83: void value expression /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/deprecated_associations.rb:84:in `deprecated_has_association_method'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/associations.rb:472:in `has_one_without_reflection'' (eval):5:in `has_one'' Is ''next'' an invalid name? ''previous'' works. Joe -- Posted via http://www.ruby-forum.com/.
''next'' is a reserved word in Ruby. ''previous'' is not a reserved word. that error is cryptic and does not really tell you much of what the cause could be. my advice is try something other than ''next'' and if it goes away, problem solved. On 3/3/06, Joe <joe@yahoo.com> wrote:> > I have this in a model: > > has_one :next, > :class_name=>''WorkPart'', > :foreign_key=>''next_id'' > > And it causes this error: > > compile error > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1 > /lib/active_record/deprecated_associations.rb:83: > void value expression > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1 > /lib/active_record/deprecated_associations.rb:84:in > `deprecated_has_association_method'' > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1 > /lib/active_record/associations.rb:472:in > `has_one_without_reflection'' > (eval):5:in `has_one'' > > > Is ''next'' an invalid name? ''previous'' works. > > Joe > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060303/fa57f730/attachment.html
It may be reserved in some situations, but I''ve used next and previous as instance methods on an AR model and had no trouble. -Jonny. Chris Hall wrote:> ''next'' is a reserved word in Ruby. ''previous'' is not a reserved word. > that > error is cryptic and does not really tell you much of what the cause > could > be. my advice is try something other than ''next'' and if it goes away, > problem solved.-- Posted via http://www.ruby-forum.com/.
I just did a quick test, and sure enough, I get the same thing. changing the association name to ''next_thing'' corrected the problem. class Thing < ActiveRecord::Base has_one :next, :class_name => ''Thing'', :foreign_key => ''next_id'' end>> t = Thing.newSyntaxError: compile error /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/deprecated_associations.rb:83: void value expression from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/deprecated_associations.rb:84:in `module_eval'' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/deprecated_associations.rb:82:in `module_eval'' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/deprecated_associations.rb:82:in `deprecated_has_association_method'' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations.rb:472:in `has_one_without_reflection'' from (eval):5:in `has_one'' from script/../config/../config/../app/models/thing.rb:2 from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:207:in `load'' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:207:in `load'' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:39:in `require_or_load'' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:22:in `depend_on'' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:178:in `require_dependency'' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:178:in `require_dependency'' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:194:in `const_missing'' from (irb):1 class Thing < ActiveRecord::Base has_one :next_thing, :class_name => ''Thing'', :foreign_key => ''next_id'' end>> t = Thing.new=> #<Thing:0x233bb7c @attributes={"next_id"=>nil, "name"=>""}, @new_record=true> so my previous answer still stands, just change the name of the association and move on. On 3/3/06, Jonathan Viney <jviney@spreydon.org.nz> wrote:> > It may be reserved in some situations, but I''ve used next and previous > as instance methods on an AR model and had no trouble. > > -Jonny. > > Chris Hall wrote: > > ''next'' is a reserved word in Ruby. ''previous'' is not a reserved word. > > that > > error is cryptic and does not really tell you much of what the cause > > could > > be. my advice is try something other than ''next'' and if it goes away, > > problem solved. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060304/aee3ca37/attachment.html
Chris, class Thing < ActiveRecord::Base has_one :next, :class_name => ''Thing'', :foreign_key => ''next_id'' end ''next'' keyword belongs to Ruby language. Change the name of your association. -- Kent On 3/4/06, Chris Hall <christopher.k.hall@gmail.com> wrote:> I just did a quick test, and sure enough, I get the same thing. changing > the association name to ''next_thing'' corrected the problem. > > class Thing < ActiveRecord::Base > has_one :next, :class_name => ''Thing'', :foreign_key => ''next_id'' > end > > >> t = Thing.new > SyntaxError: compile error > /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/deprecated_associations.rb:83: > void value expression > from /usr/lib/ruby/gems/1.8/gems/activerecord- > 1.13.2/lib/active_record/deprecated_associations.rb:84:in > `module_eval'' > from > /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/deprecated_associations.rb:82:in > `module_eval'' > from /usr/lib/ruby/gems/1.8/gems/activerecord- > 1.13.2/lib/active_record/deprecated_associations.rb:82:in > `deprecated_has_association_method'' > from > /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations.rb:472:in > `has_one_without_reflection'' > from (eval):5:in `has_one'' > from > script/../config/../config/../app/models/thing.rb:2 > from > /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:207:in > `load'' > from > /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:207:in > `load'' > from > /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:39:in > `require_or_load'' > from > /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:22:in > `depend_on'' > from > /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:178:in > `require_dependency'' > from > /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:178:in > `require_dependency'' > from > /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:194:in > `const_missing'' > from (irb):1 > > > class Thing < ActiveRecord::Base > has_one :next_thing, :class_name => ''Thing'', :foreign_key => ''next_id'' > end > > >> t = Thing.new > => #<Thing:0x233bb7c @attributes={"next_id"=>nil, "name"=>""}, > @new_record=true> > > so my previous answer still stands, just change the name of the association > and move on. > > > On 3/3/06, Jonathan Viney < jviney@spreydon.org.nz> wrote: > > It may be reserved in some situations, but I''ve used next and previous > > as instance methods on an AR model and had no trouble. > > > > -Jonny. > > > > Chris Hall wrote: > > > ''next'' is a reserved word in Ruby. ''previous'' is not a reserved word. > > > that > > > error is cryptic and does not really tell you much of what the cause > > > could > > > be. my advice is try something other than ''next'' and if it goes away, > > > problem solved. > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Hi -- On Sat, 4 Mar 2006, Jonathan Viney wrote:> Chris Hall wrote: >> ''next'' is a reserved word in Ruby. ''previous'' is not a reserved word. >> that >> error is cryptic and does not really tell you much of what the cause >> could >> be. my advice is try something other than ''next'' and if it goes away, >> problem solved. > > It may be reserved in some situations, but I''ve used next and previous > as instance methods on an AR model and had no trouble.You may be able to define it explicitly, but when it''s an association name, AR tries to write a method like this, and runs into this error (shown here in irb):>> def has_next?; !next.nil?; endSyntaxError: compile error (irb):3: void value expression def has_next?; !next.nil?; end ^ David -- David A. Black (dblack@wobblini.net) Ruby Power and Light (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black
David, bravo! there''s the reason. Chris. On 3/4/06, dblack@wobblini.net <dblack@wobblini.net> wrote:> > Hi -- > > On Sat, 4 Mar 2006, Jonathan Viney wrote: > > > Chris Hall wrote: > >> ''next'' is a reserved word in Ruby. ''previous'' is not a reserved word. > >> that > >> error is cryptic and does not really tell you much of what the cause > >> could > >> be. my advice is try something other than ''next'' and if it goes away, > >> problem solved. > > > > It may be reserved in some situations, but I''ve used next and previous > > as instance methods on an AR model and had no trouble. > > You may be able to define it explicitly, but when it''s an association > name, AR tries to write a method like this, and runs into this error > (shown here in irb): > > >> def has_next?; !next.nil?; end > SyntaxError: compile error > (irb):3: void value expression > def has_next?; !next.nil?; end > ^ > > David > > -- > David A. Black (dblack@wobblini.net) > Ruby Power and Light (http://www.rubypowerandlight.com) > > "Ruby for Rails" chapters now available > from Manning Early Access Program! http://www.manning.com/books/black > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060304/b558e6e4/attachment.html