It might be ORM problem

3 views
Skip to first unread message

sadeesh kumar

unread,
Jul 12, 2008, 5:26:15 AM7/12/08
to Ruby on Rails: Talk
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.

Matthew Rudy Jacobs

unread,
Jul 12, 2008, 7:35:08 AM7/12/08
to rubyonra...@googlegroups.com
sadeesh kumar wrote:
> 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 >
>
> 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.

Does the `users` table have a `city` column?
What does the User model look like?
What does the `create_users.rb` migration look like?
If you run it in console, does it work?
In console, when you just do >> User, what response do you get?
--
Posted via http://www.ruby-forum.com/.

sadeesh kumar

unread,
Jul 12, 2008, 8:27:26 AM7/12/08
to Ruby on Rails: Talk
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
---------
class User < ActiveRecord::Base

validates_presence_of :first_name, :last_name, :password, :mail_id, :city, :state, :country, :street, :zipcode
validates_confirmation_of :password, :mail_id
validates_format_of :mail_id, :with => /^(\w+@[a-zA-Z_]+?\.[a-zA-Z]
{2,6})$/
validates_uniqueness_of :mail_id, :on => :create, :message => "is
not available"
validates_length_of :first_name, :last_name, :maximum => 30
validates_length_of :password, :minimum => 8
validates_format_of :zipcode, :with => /^([0-9]{5,6}|[0-9]{5}[-]{1}
[0-9]{4})$/
validates_numericality_of :annual_income
end.

> What does the `create_users.rb` migration look like?

I am not using migration. I will simply execute the script generated
by my db designer.

> If you run it in console, does it work?
> In console, when you just do >> User, what response do you get?

I got a blank line.

Thanks,
-Sadeesh kumar

Andrew Roth

unread,
Jul 12, 2008, 10:38:27 AM7/12/08
to Ruby on Rails: Talk
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.

Andrew Roth

unread,
Jul 12, 2008, 10:46:17 AM7/12/08
to Ruby on Rails: Talk
> 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.

sadeesh kumar

unread,
Jul 12, 2008, 10:55:47 AM7/12/08
to Ruby on Rails: Talk
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

sadeesh kumar

unread,
Jul 12, 2008, 10:58:35 AM7/12/08
to Ruby on Rails: Talk
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

Frederick Cheung

unread,
Jul 12, 2008, 2:57:42 PM7/12/08
to Ruby on Rails: Talk


On Jul 12, 3:58 pm, sadeesh kumar <sadath...@gmail.com> wrote:
> 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

sadeesh kumar

unread,
Jul 14, 2008, 1:57:37 AM7/14/08
to Ruby on Rails: Talk
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.

Frederick Cheung

unread,
Jul 14, 2008, 3:17:22 AM7/14/08
to Ruby on Rails: Talk
> 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

sadeesh kumar

unread,
Jul 14, 2008, 4:42:32 AM7/14/08
to Ruby on Rails: Talk
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.

Matthew Rudy Jacobs

unread,
Jul 14, 2008, 4:47:05 AM7/14/08
to rubyonra...@googlegroups.com
sadeesh kumar wrote:
> 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 >

> Thanks,
> -Sadeesh.

Hmm....
there's something really wrong.

Try creating a new project

"rails newproject"

and create each bit of your current project bit by bit.
doing it all with the "script/generate model Profile user_id:integer
name:string"
type generators.

and check that it works,
bit by bit...

and put the plugin back in place.


hopefully you can debug what's going wrong,
or if generally your Rails install is broken
(should be apparent after you create your first model)

sadeesh kumar

unread,
Jul 14, 2008, 7:15:11 AM7/14/08
to Ruby on Rails: Talk
k Matthew,
I do the same.
Thanks,
-Sadeesh.

On Jul 14, 1:47 pm, Matthew Rudy Jacobs <rails-mailing-l...@andreas-
Reply all
Reply to author
Forward
0 new messages