Tod Karpinski
2005-Sep-25 12:16 UTC
Problem issue with belongs_tohas_one and error_message_on
Hello I have a problem with relationship with belongs_to - has_one and with error_message_on I have splitted one huge table users into two tables user and profile. In users I''m keeping main fields like id,email,password and in profile there are the rest of fields. Table users: id,email,password Table profiles: id,user_id,publicname, and more ... My models are: - user.rb has_one :profile - profile.rb belongs_to :user Briefly User controller looks like . class UserController < ApplicationController model :user, :profile def register @user = User.new(params[:user]) if request.post? and @user.save end end end With this it doesn''t save values in table specialists. In register.rhtml I have <%= error_message_on("user", "email") %> - This shows info <%= error_message_on("profile", "publicname") %> - With this it doesn''t work an I''m getting such an error "NoMethodError in User#register" It seems like, there is no working associations beetwen users and profiles. The only thing I''ve managed is small change I''ve made to UserController def register @user = User.new(params[:user]) @user.profile = Profile.new(params[:profile]) if request.post? and @user.save end end So it saves into users and profile, but I''m still getting error if in register.rhtml is <%= error_message_on("profile", "publicname") %> And still doesn''t work all validates_* I''ve put into model profile.rb. So sed, but after all this strugling with this still I''m in begining of work. Please be kind to me and I beg You all the Railers for help Best Greatings
Duane Johnson
2005-Sep-26 14:41 UTC
Re: Problem issue with belongs_tohas_one and error_message_on
On Sep 25, 2005, at 5:16 AM, Tod Karpinski wrote:> Hello > > I have a problem with relationship with belongs_to - has_one and with > error_message_on > > I have splitted one huge table users into two tables user and profile. > In users I''m keeping main fields like id,email,password and in > profile there are > the rest of fields. > > Table users: > id,email,password > > Table profiles: > id,user_id,publicname, and more ... > > > My models are: > - user.rb > has_one :profile > > - profile.rb > belongs_to :user > > > Briefly User controller looks like . > > class UserController < ApplicationController > model :user, :profile > > def register > @user = User.new(params[:user]) > > if request.post? and @user.save > end > end > end > > With this it doesn''t save values in table specialists. > > In register.rhtml I have > <%= error_message_on("user", "email") %> - This shows info > > <%= error_message_on("profile", "publicname") %> - With this it > doesn''t work an > I''m getting such an error "NoMethodError in User#register" >It doesn''t look like you''ve assigned @profile in your controller. Try this: @profile = @user.profile Your error_message_on call should work then.> > It seems like, there is no working associations beetwen users and > profiles. > > The only thing I''ve managed is small change I''ve made to > UserController > def register > @user = User.new(params[:user]) > @user.profile = Profile.new(params[:profile]) > > if request.post? and @user.save > end > end > > So it saves into users and profile, but I''m still getting error if in > register.rhtml is <%= error_message_on("profile", "publicname") %> > And still doesn''t work all validates_* I''ve put into model profile.rb. > > > So sed, but after all this strugling with this still I''m in > begining of work. > > > Please be kind to me and I beg You all the Railers for help > > > Best Greatings > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Tod Karpinski
2005-Sep-27 02:18 UTC
Re: Problem issue with belongs_tohas_one and error_message_on
Thanks for help> It doesn''t look like you''ve assigned <at> profile in your controller. > Try this: > > <at> profile = <at> user.profile > > Your error_message_on call should work then.But it doesn''t solved the problem With Your added line I have noticed strange behavior on my RoR, although it should already work now. But ... If I remove all validates_* from model profile.rb, it saves data as before into users and profiles. If I let validates_* I can notice that validates_* are ''WORKING'' and restraining from saving data into profiles but still datas are saved into users. On top of that calling error_message_on only for profile still doesn''t work. Hmm, how bad, what I have missed in my few lines code. Please, Duane Johnson be kind and patient to me, and share Your wisdom with me :)
Reasonably Related Threads
- Overloading error_message_on method in ActiveRecordHelper
- error_message_on broken?
- Re: RESOLVED: Overloading error_message_on method in ActiveRecordHelper
- error_message_on / error_messages_for
- Possibly OT: intermittently long response times when connecting to host