:class_name should be the name, ie :class_name => ‘Temp’
Also make sure that your Temp class is in temp.rb
User::Temp (NameError)
from test.rb:17
which indicates the <compose_of> method to be mistaken , i check the
rails API, but the the LATEST rails API is 2007 Dec on http://www.rubyonrail.com
, is the API Rails 1.X ? Have not updated to rails 2.0 yet?
it’s all in test.rb before i write this , as your suggestion, i put
Temp class into temp.rb file,but still not working , still some
error :
test.rb:2:Warning: require_gem is obsolete. Use gem instead.
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
aggregations.rb:171:in `x=': undefined method `constantize' for
Temp:Class (NoMethodError)
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2117:in `send'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2117:in `attributes='
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2116:in `each'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2116:in `attributes='
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:1926:in `initialize'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:571:in `new'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:571:in `create'
from test.rb:19
it’s all in one test.rb before , now the Temp class has moved to
temp.rb , but still some errors ,why?
test.rb:2:Warning: require_gem is obsolete. Use gem instead.
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
aggregations.rb:171:in `attr=': undefined method `constantize' for
Temp:Class (NoMethodError)
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2117:in `send'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2117:in `attributes='
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2116:in `each'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2116:in `attributes='
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:1926:in `initialize'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:571:in `new'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:571:in `create'
from test.rb:19
which indicates the line <% User.create(:attr=>temp) %> to be mistaken
it’s all in one test.rb before , now the Temp class has moved to
temp.rb , but still some errors ,why?
test.rb:2:Warning: require_gem is obsolete. Use gem instead.
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
aggregations.rb:171:in `attr=': undefined method `constantize' for
Temp:Class (NoMethodError)
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2117:in `send'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2117:in `attributes='
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2116:in `each'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2116:in `attributes='
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:1926:in `initialize'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:571:in `new'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:571:in `create'
from test.rb:19
which indicates the line <% User.create(:attr=>temp) %> to be
mistaken
Can you show us all of your Temp class please, and the code that you’re
using to get that error, and any other model that defines a relationship
with the Temp class. It looks possible to me that you’re doing
:class_name
=> Temp, when it should be :class_name => “Temp”. I think that’s where I
recall getting an error message like that from.
sorry to say , that still not right after changing
test.rb:2:Warning: require_gem is obsolete. Use gem instead.
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
base.rb:2177:in `sort': undefined method `<=>' for :name:Symbol
(NoMethodError)
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2177:in `attribute_names'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2458:in `clone_attributes'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2126:in `attributes'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2338:in `attributes_with_quotes'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2262:in `create_without_callbacks'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/callbacks.rb:226:in `create_without_timestamps'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/timestamp.rb:29:in `create'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2238:in `create_or_update_without_callbacks'
... 8 levels...
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/transactions.rb:120:in `rollback_active_record_state!'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/transactions.rb:108:in `save'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:572:in `create'
from test.rb:19
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On May 19, 1:54 pm, "Ryan B. (Radar)" <[email protected]>
oh no , not again , Railsy or not , anyway , i’m still learning
test.rb:2:Warning: require_gem is obsolete. Use gem instead.
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
base.rb:2177:in `sort': undefined method `<=>' for :name:Symbol
(NoMethodError)
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2177:in `attribute_names'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2458:in `clone_attributes'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2126:in `attributes'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2338:in `attributes_with_quotes'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2262:in `create_without_callbacks'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/callbacks.rb:226:in `create_without_timestamps'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/timestamp.rb:29:in `create'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2238:in `create_or_update_without_callbacks'
... 8 levels...
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/transactions.rb:120:in `rollback_active_record_state!'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/transactions.rb:108:in `save'
from d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:572:in `create'
from test.rb:19
No that’s not how you create a Rails app. You have to firstly generate
the
skeleton for the rails app. Read through the tutorial, it should teach
you a
few things.
Where are you calling sort? It’s pointing to line 19 in your test.rb,
which
looks to me to be the call to create.
Ok, do you want to make this more railsy? Your models don’t appear to be
in
a rails directory at all, and the way you are establishing the
connection
and defining the model in the same file is not very neat. I suggest
reading
through a Rails tutorial, I’ve begun to write a large one myself and
that
should kick start you on the path to enlightenment: frozenplague.net Just click through
the
pages in the right menu, they are in the proper order, ignoring the
Frequently Asked Questions and Lovely People pages.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.