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 Palmer 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 Bush wrote:

Jimmy Palmer 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.

Jimmy Palmer 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 Bush wrote:

Jimmy Palmer 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.

Mark Bush wrote:

Jimmy Palmer 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 Palmer 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 Bush wrote:

Jimmy Palmer 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 Palmer wrote:

strange stuff...never seen this before.

Neither have I. Sorry.

Hi --

David A. Black wrote:

Hi --

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.

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 Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

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?

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

Everything is working fine... except me :smiley: