Update_attributes not updating

For some strange reason I can’t get update_attributes to work. Any
reason why that might be?

here is my code:

controller:

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

respond_to do |format|
  if @user.update_attributes(params[:user])

    flash[:notice] = 'Your Information was successfully updated.'
    format.html { redirect_to(user_url(@user)) }
    format.xml  { head :ok }
  else
    format.html { render :action => "edit" }
    format.xml  { render :xml => @user.errors, :status =>

:unprocessable_entity }
end
end
end

view:

<% form_for(:user, :url => user_url(@user), :html => { :method => :put
}) do |f| %>

  <div class="optional">
  <label for="city">First Name:</label>
    <%= f.text_field :first_name, :class => 'inputText' %>
</div>
<div class="optional">
  <label for="city">Last Name:</label>
    <%= f.text_field :last_name, :class => 'inputText' %>
</div>
<p>
  <%=submit_tag "Update"%>
</p>

<% end %>

Jimmy P. wrote:

For some strange reason I can’t get update_attributes to work. Any
reason why that might be?

Any error messages in your logs? What are the parameters recorded in
the log file that are passed into the #update call?

You can also try using #update_attributes! so that an exception is
raised which may give more information in your log file as to the
problem…

Mark B. wrote:

Jimmy P. wrote:

For some strange reason I can’t get update_attributes to work. Any
reason why that might be?

Any error messages in your logs? What are the parameters recorded in
the log file that are passed into the #update call?

You can also try using #update_attributes! so that an exception is
raised which may give more information in your log file as to the
problem…

That’s the thing…I’ve even put it in debug model and every thing seems
to be correct. I tried the update_attributes! but no exception was
raised.

Mark B. wrote:

Jimmy P. wrote:

That’s the thing…I’ve even put it in debug model and every thing seems
to be correct. I tried the update_attributes! but no exception was
raised.

Interesting.

Have you tried calling #update_attributes on something from the
application console (script/console)?

yeah…tried that and it returned true but didn’t update the object.

strange.

Jimmy P. wrote:

That’s the thing…I’ve even put it in debug model and every thing seems
to be correct. I tried the update_attributes! but no exception was
raised.

Interesting.

Have you tried calling #update_attributes on something from the
application console (script/console)?

Mark B. wrote:

Jimmy P. wrote:

yeah…tried that and it returned true but didn’t update the object.

What does your log file show when you try this? Does it show the UPDATE
SQL call?

it does call it both from the console and the browser but it has the old
values.

Jimmy P. wrote:

yeah…tried that and it returned true but didn’t update the object.

What does your log file show when you try this? Does it show the UPDATE
SQL call?

Jimmy P. wrote:

it does call it both from the console and the browser but it has the old
values.

Sounds like something fundamental is playing up. What DB adapter are
you using? What versions of rails and activerecord?

Mark B. wrote:

Jimmy P. wrote:

it does call it both from the console and the browser but it has the old
values.

Sounds like something fundamental is playing up. What DB adapter are
you using? What versions of rails and activerecord?

this is weird. I added a couple more columns to my form and they
updated fine. I added more and they would not update. I haven’t found
a pattern yet, but still am digging.

I’m using 2.0.2 and mysql.

strange stuff…never seen this before.

Jimmy P. wrote:

strange stuff…never seen this before.

Neither have I. Sorry.

David A. Black wrote:

Hi –

On Mon, 3 Mar 2008, Jimmy P. wrote:

updated fine. I added more and they would not update. I haven’t found
a pattern yet, but still am digging.

I’m using 2.0.2 and mysql.

strange stuff…never seen this before.

Can you post some of the non-working code? I’m just curious whether
one might spot something. Also, do you have validations in your
models? Not that that would necessarily account for what you’re
describing, but just to get a fuller picture.

David

I found my problem. Thanks for the help.

Hi –

On Mon, 3 Mar 2008, Jimmy P. wrote:

updated fine. I added more and they would not update. I haven’t found
a pattern yet, but still am digging.

I’m using 2.0.2 and mysql.

strange stuff…never seen this before.

Can you post some of the non-working code? I’m just curious whether
one might spot something. Also, do you have validations in your
models? Not that that would necessarily account for what you’re
describing, but just to get a fuller picture.

David


Upcoming Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS, April 14-17 2008, New York City
CORE RAILS, June 24-27 2008, London (Skills Matter)
See http://www.rubypal.com for details. Berlin dates coming soon!

On Mar 3, 2008, at 1:11 PM, Jimmy P. wrote:

strange stuff…never seen this before.

Can you post some of the non-working code? I’m just curious whether
one might spot something. Also, do you have validations in your
models? Not that that would necessarily account for what you’re
describing, but just to get a fuller picture.

David

I found my problem. Thanks for the help.

OK, so tell the list what it was. That’s only fair. It let’s those
who do use the search features of the Internet to find solutions as
well as problems and provides a bit of closure to everyone who’s tried
to help (or just had to delete the email; yes, many use email rather
than the forum).

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Jimmy, what did you change to get it to work?

I have the same problem and it’s only the :first_name and :last_name
fields that are not updating.

On Mar 3, 11:11 am, Jimmy P. [email protected]

I have a similar problem here.

The SQL generated is perfect, but one of my models refuses to get
updated.

Got attr_protected on one of your model attributes?

On 11/09/2008, at 20:05, Fernando P.
<[email protected]

Argh! I’m so stupid! I was updating a field and displaying another one
which remains constant.

Everything is working fine… except me :smiley: