It might be ORM problem

Hi,
   I have a model user.rb, a controller userdata_controller, methods
in the controller and respective .rhtml files. I created a
registration page. Saved into users table and it works fine. But
sometimes its throwing error as

undefined method `city=' for #<User >

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
attribute_methods.rb:251:in `method_missing'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2361:in `send'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2361:in `attributes='
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2360:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2360:in `attributes='
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2130:in `initialize'
app/controllers/matrimony_controller.rb:124:in `new'
app/controllers/matrimony_controller.rb:124:in `useraccount'
-e:2:in `load'
-e:2

It assumes that there is no field 'city' in table users.
I confused a lot. It is never working until i restart my mongrel. I am
not able to predict, when the problem rises.

Any idea? Help me..

Thanks,
-Sadeesh kumar.

Hi Matthew,

Does the `users` table have a `city` column?

Yes,
  My table have 'city' column. and i am able to save user data, when
he do registration.This problem occurs on only at particular
scenario.Just now I found a scenario, Which is

1.When i try to go to (action)registration page by clicking the link,
then the registration process works well.
2.When i try to go to same (action)registration page by redirecting
from another action(based on condition whether the user has logged in
or not), then the registration process fails when i do save the user.

What does the User model look like?

user.rb

Do you see anything in the log file when it gives undefined method
that might give a clue?

What deployment system are you using? Try running webrick and test
there, if the problem doesn't happen, then it's probably something
with your production deployment.

1.When i try to go to (action)registration page by clicking the link,
then the registration process works well.
2.When i try to go to same (action)registration page by redirecting
from another action(based on condition whether the user has logged in
or not), then the registration process fails when i do save the user.

Hmm, that's strange. The only thing I can think of is that the
redirection is setting a session variable or cookie or some other
persistent data that's messing up the process.

No roth,
    Problem comes with webrick also. And i am in development mode
only. I could found the below one in my log file,

NoMethodError (undefined method `city=' for #<User >):
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/attribute_methods.rb:251:in `method_missing'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/base.rb:2361:in `send'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/base.rb:2361:in `attributes='
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/base.rb:2360:in `each'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/base.rb:2360:in `attributes='
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/base.rb:2130:in `initialize'
    /app/controllers/matrimony_controller.rb:124:in `new'
    /app/controllers/matrimony_controller.rb:124:in `useraccount'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:1162:in `send'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:1162:in `perform_action_without_filters'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/filters.rb:580:in `call_filters'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/filters.rb:573:in `perform_action_without_benchmark'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
    c:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/rescue.rb:201:in `perform_action_without_caching'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/caching/sql_cache.rb:13:in `perform_action'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/connection_adapters/abstract/query_cache.rb:33:in
`cache'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/query_cache.rb:8:in `cache'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/caching/sql_cache.rb:12:in `perform_action'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:529:in `send'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:529:in `process_without_filters'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/filters.rb:569:in
`process_without_session_management_support'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/session_management.rb:130:in `process'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:389:in `process'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:149:in `handle_request'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:107:in `dispatch'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:104:in `synchronize'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:104:in `dispatch'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:120:in `dispatch_cgi'
    c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:35:in `dispatch'
    c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:
112:in `handle_dispatch'
    c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:
78:in `service'
    c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'
    c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
    c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'
    c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'
    c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
    c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'
    c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:
62:in `dispatch'
    c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/
webrick.rb:66
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/
active_support/dependencies.rb:509:in `require'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/
active_support/dependencies.rb:354:in `new_constants_in'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/
active_support/dependencies.rb:509:in `require'
    c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:
39
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
    ./script/server:3
    -e:2:in `load'
    -e:2

Rendering c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/templates/rescues/layout.erb (internal_server_error)

my scenarios are this,
1.When i try to go to (action)registration page by clicking the link,
then the registration process works well.
2.When i try to go to same (action)registration page by redirecting
from another action(based on condition whether the user has logged in
or not), then the registration process fails when i do save the user.

   If i follow the first scenario, no problem.
   If i follow the second scenario, problem rises.
   If i follow the first scenario after did the second scenario,
problem rises still.

Looking for your billion dollar answer.
Thanks,
-Sadeesh

my scenarios are this,
1.When i try to go to (action)registration page by clicking the link,
then the registration process works well.
2.When i try to go to same (action)registration page by redirecting
from another action(based on condition whether the user has logged in
or not), then the registration process fails when i do save the user.

   start the server and If i follow the first scenario, no problem.
   restart the server and If i follow the second scenario, problem
rises.
   restart the server and If i follow the first scenario after did the
second scenario,
problem rises still.

Looking for your billion dollar answer.
Thanks,
-Sadeesh

my scenarios are this,
1.When i try to go to (action)registration page by clicking the link,
then the registration process works well.
2.When i try to go to same (action)registration page by redirecting
from another action(based on condition whether the user has logged in
or not), then the registration process fails when i do save the user.

Does it go away if you change cache_classes to true in development.rb?

Fred

Hi Frederick,
       First of all thanks for your reply.Your answer is great and it
resolved my problem partially for the below one.
-----8<-------

my scenarios are this,
1.When i try to go to (action)registration page by clicking the link,
then the registration process works well.
2.When i try to go to same (action)registration page by redirecting
from another action(based on condition whether the user has logged in
or not), then the registration process fails when i do save the user.

Does it go away if you change cache_classes to true in development.rb?
Fred

------>8--------

Yes, it gets away after I made cache_classes = true in development.rb.
But it has been fixed partially. Now what is the real problem is,

1.If I follow the first scenario as usual no problem and if I continue
the second scenario, it works(because of your suggestion).
2.If I directly do the second scenario, problem rises and If I
continue the first one then also problem rises. I could able to do
nothing then after.

Can you explain me why? looking for your reply Frederick,

Thanks,
-Sadeesh kumar.

Yes, it gets away after I made cache_classes = true in development.rb.
But it has been fixed partially. Now what is the real problem is,

1.If I follow the first scenario as usual no problem and if I continue
the second scenario, it works(because of your suggestion).
2.If I directly do the second scenario, problem rises and If I
continue the first one then also problem rises. I could able to do
nothing then after.

This means you are confusing the dependencies mechanism. This usually
means that either:
- You have got plugins hanging on to references to one of your model
classes or instances of it
- You're explicitly requiring a class (ie using require), which
sidesteps rails' dependency stuff.

Fred

Fred,
    I am using only one plugin simple_captcha. And I never explicitly
requiring a class in my app.
   Now I am in new problem which is I am having model profile.rb and
table named profiles. If I tend to do like below,

   current_profile = Profile.new("from_user_id" =>
session[:user_id],"to_user_id" => 5)
   current_profile.save

   then it throws similar problem,
    NoMethodError in MatrimonyController#forwardprofiles

undefined method `to_user_id=' for #<Profile >

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
attribute_methods.rb:251:in `method_missing'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2361:in `send'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2361:in `attributes='
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2360:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2360:in `attributes='
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2130:in `initialize'
app/controllers/matrimony_controller.rb:52:in `new'
app/controllers/matrimony_controller.rb:52:in `forwardprofiles'
app/controllers/matrimony_controller.rb:49:in `each'
app/controllers/matrimony_controller.rb:49:in `forwardprofiles'
-e:2:in `load'
-e:2

By comparing this with the previous one, do you have any Idea?

Thanks,
-Sadeesh.

k Matthew,
      I do the same.
Thanks,
-Sadeesh.