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 #

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:insend’
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:ineach’
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:ininitialize’
app/controllers/matrimony_controller.rb:124:in new' app/controllers/matrimony_controller.rb:124:inuseraccount’
-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.

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 #

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?

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 => /^(\[email protected][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

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.

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.

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:inmethod_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:inattributes=’
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:inattributes=’
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:innew’
/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:insend’
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:incall_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:inperform_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:inperform_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:inperform_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:incache’
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:insend’
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:inprocess_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:inprocess’
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:indispatch’
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:indispatch’
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:indispatch’
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:inservice’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in each' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:instart’
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:ingem_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:inrequire’
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:inrequire’
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:inrequire’
./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

On Jul 12, 3:58 pm, sadeesh kumar [email protected] 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

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 #

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:insend’
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:ineach’
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:ininitialize’
app/controllers/matrimony_controller.rb:52:in new' app/controllers/matrimony_controller.rb:52:inforwardprofiles’
app/controllers/matrimony_controller.rb:49:in each' app/controllers/matrimony_controller.rb:49:inforwardprofiles’
-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.

On Jul 14, 1:47 pm, Matthew R. Jacobs <rails-mailing-l…@andreas-

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 #

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)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs