As suggested in an earlier post I''ve extended the login generator model to handle a few extra fields. Now I''m experimenting and modifying my view template. I''ve only included one field in my form but I''m basically following the exact steps shown in the form helper section of "Agile Web Programming". By that I mean in my controller I''m using if user.update_attributes(params[:user]) flash[:notice] = ''changes saved'' else render :action=> ''error'' end to save the changes. However this does not work and falls through to my error page. To try and understand whats going on, I saved only 1 field by using: user.update_attribute("email", "test value") and that worked perfectly, so I feel that the majority of my code is correct. The webform I am using does not represent a full user record, only some of the fields. Does update_attributes require that I update an entire record? Could that be why it fails in my first case? Thanks, Gary
Ronny Hanssen
2005-Sep-06 09:47 UTC
Re: question about update_attributes and update_attribute
I am still a noob in rails, but as long as the data you have can be saved in a record I guess it should work. I mean, if you are missing some fields, and the database doesn't allow NULL for that field then I guess you have a problem. I think errors are reported in the error property (or was it errors?). Ronny On 9/6/05, Gary Huntress <ghuntress@comcast.net> wrote:> > As suggested in an earlier post I've extended the login generator model to > handle a few extra fields. Now I'm experimenting and modifying my view > template. I've only included one field in my form but I'm basically > following the exact steps shown in the form helper section of "Agile Web > Programming". By that I mean in my controller I'm using > > if user.update_attributes(params[:user]) > flash[:notice] = 'changes saved' > else > render :action=> 'error' > end > > to save the changes. However this does not work and falls through to my > error page. > > To try and understand whats going on, I saved only 1 field by using: > > user.update_attribute("email", "test value") > > and that worked perfectly, so I feel that the majority of my code is > correct. > > The webform I am using does not represent a full user record, only some of > the fields. Does update_attributes require that I update an entire record? > Could that be why it fails in my first case? > > > Thanks, > > Gary > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Maybe @ before params? On 9/6/05, Ronny Hanssen <super.ronny@gmail.com> wrote:> I am still a noob in rails, but as long as the data you have can be saved in > a record I guess it should work. I mean, if you are missing some fields, and > the database doesn't allow NULL for that field then I guess you have a > problem. I think errors are reported in the error property (or was it > errors?). > > Ronny > > > On 9/6/05, Gary Huntress <ghuntress@comcast.net> wrote: > > As suggested in an earlier post I've extended the login generator model to > > handle a few extra fields. Now I'm experimenting and modifying my view > > template. I've only included one field in my form but I'm basically > > following the exact steps shown in the form helper section of "Agile Web > > Programming". By that I mean in my controller I'm using > > > > if user.update_attributes(params[:user]) > > flash[:notice] = 'changes saved' > > else > > render :action=> 'error' > > end > > > > to save the changes. However this does not work and falls through to my > > error page. > > > > To try and understand whats going on, I saved only 1 field by using: > > > > user.update_attribute("email", "test value") > > > > and that worked perfectly, so I feel that the majority of my code is > > correct. > > > > The webform I am using does not represent a full user record, only some of > > the fields. Does update_attributes require that I update an entire > record? > > Could that be why it fails in my first case? > > > > > > Thanks, > > > > Gary > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
François Beausoleil
2005-Sep-06 13:09 UTC
Re: question about update_attributes and update_attribute
Hello Gary, Gary Huntress said the following on 2005-09-06 00:07:> if user.update_attributes(params[:user]) > flash[:notice] = ''changes saved'' > else > render :action=> ''error'' > end > > to save the changes. However this does not work and falls through to > my error page. > > To try and understand whats going on, I saved only 1 field by using: > > user.update_attribute("email", "test value") > > and that worked perfectly, so I feel that the majority of my code is > correct.In your error view, do you show the errors ? They might give you a clue as to what''s going on. Try <%= error_messages_for ''user'' %>, and don''t forget to make user an instance variable (@user) so it can be used in the error view. Alternatively, log the errors collection: if # update code # Great ! else logger.error user.errors.full_messages.inspect render :action => ''error'' end Hope that helps ! François
Wilson Bilkovich
2005-Sep-06 21:19 UTC
Re: question about update_attributes and update_attribute
Everyone keeps telling me I''m wrong on the IRC channel, but my strong belief is that update_attributes sets nils out any attribute not included in the hash that you pass it. Nobody has been able to explain the behavior of that method to me, so I''ve removed all references to it in my Rails apps. On 9/6/05, Gary Huntress <ghuntress-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> As suggested in an earlier post I''ve extended the login generator model to > handle a few extra fields. Now I''m experimenting and modifying my view > template. I''ve only included one field in my form but I''m basically > following the exact steps shown in the form helper section of "Agile Web > Programming". By that I mean in my controller I''m using > > if user.update_attributes(params[:user]) > flash[:notice] = ''changes saved'' > else > render :action=> ''error'' > end > > to save the changes. However this does not work and falls through to my > error page. > > To try and understand whats going on, I saved only 1 field by using: > > user.update_attribute("email", "test value") > > and that worked perfectly, so I feel that the majority of my code is > correct. > > The webform I am using does not represent a full user record, only some of > the fields. Does update_attributes require that I update an entire record? > Could that be why it fails in my first case? > > > Thanks, > > Gary > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >