Forum: Ruby on Rails update command not updating DB

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bryan C. (Guest)
on 2006-01-04 01:41
I really need your help guys... I spent 6 hours on this simple update
command today that should work. It works fine in my other controller,
but doesn't work in this one for some reason.

Here is my controller code for the list view, and then the update
command:

======
def edit
    @user = User.find(params[:id])
  end

  def update
    @user = User.find(params[:id])

    if @user.update_attributes(@params[:users])
      redirect_to(:action => "save_account")
    else
      flash[:notice] = "Couldn't save account information, please try
again."
      redirect_to(:action => 'edit', :id => @user.id)
    end
  end
======

if I set up a template for update and inspect both @user and
params[:user] this is what I get, in that same order:

======
#"test s address", "shipping_state"=>"te", "billing_street"=>"16409",
"billing_city"=>"test", "website"=>"www.test.com",
"shipping_country"=>"test", "shipping_zip"=>"test", "id"=>"51",
"shipping_city"=>"test", "shipping_option"=>"1", "billing_state"=>"te",
"phone"=>"tttttttest", "billing_country"=>"test", "billing_zip"=>"test",
"studio_name"=>"test studio", "shipping_street"=>"test",
"password"=>"4f939b7b470595d4c9924342ad57821cc818deac", "login"=>"test",
"email"=>"removed_email_address@domain.invalid"}>

--------------

{"shipping_state"=>"te", "studio_address"=>"test s address",
"billing_street"=>"testing", "billing_city"=>"test",
"website"=>"www.test.com", "shipping_zip"=>"test",
"shipping_country"=>"test", "billing_state"=>"te",
"shipping_city"=>"test", "shipping_option"=>"1", "phone"=>"tttttttest",
"billing_country"=>"test", "billing_zip"=>"test", "studio_name"=>"test
studio", "shipping_street"=>"test"}
=======

Why is it that my @user starts with a # and never tells it that the
"test s address" is the studio address? Also, why does it end with }>? I
think my @user variable is why my .update_attributes command is failing
and never telling the SQL server to update itself. You will notice that
in my params I don't include password, login, or email.... but that is
because this is just editing user info and I don't want re-access to
that info. Can someone please help me. Thanks a lot.
Mark Reginald J. (Guest)
on 2006-01-04 02:25
(Received via mailing list)
Bryan C. wrote:

>     if @user.update_attributes(@params[:users])

Perhaps your problem is that you're using @params here
rather than the params method which can handle both
symbol and string keys.

--
We develop, watch us RoR, in numbers too big to ignore.
Bryan C. (Guest)
on 2006-01-04 04:49
Mark Reginald J. wrote:
> Bryan C. wrote:
>
>>     if @user.update_attributes(@params[:users])
>
> Perhaps your problem is that you're using @params here
> rather than the params method which can handle both
> symbol and string keys.
>
> --
> We develop, watch us RoR, in numbers too big to ignore.

I have used @params[:user], @params["users"], and params[:users]... each
to no avail. Anyone?
Lance B. (Guest)
on 2006-01-04 04:58
(Received via mailing list)
On 1/3/06, Mark Reginald J. <removed_email_address@domain.invalid> wrote:
>
> >     if @user.update_attributes(@params[:users])
>

Is it just a typo that you are referencing @params[:users] here and
@params[:user] elsewhere in your message?
Bryan C. (Guest)
on 2006-01-04 05:28
Lance B. wrote:
> On 1/3/06, Mark Reginald J. <removed_email_address@domain.invalid> wrote:
>>
>> >     if @user.update_attributes(@params[:users])
>>
>
> Is it just a typo that you are referencing @params[:users] here and
> @params[:user] elsewhere in your message?


Yes, just a typo, sorry.
Justin F. (Guest)
on 2006-01-06 22:40
(Received via mailing list)
Bryan C. wrote:
>   end
>     end
> "shipping_city"=>"test", "shipping_option"=>"1", "billing_state"=>"te",
> "shipping_country"=>"test", "billing_state"=>"te",
> because this is just editing user info and I don't want re-access to
> that info. Can someone please help me. Thanks a lot.
>

Look carefully at where you put your inspecting code in the template -
it looks to me as if it was inside an HTML helper call, so that the part
up to the first => in the @user was hidden inside the tag, and you have
ended up with }> in the content.

Doing View Source in the browser might help you to diagnose this.

regards

   Justin
This topic is locked and can not be replied to.