Newbie: Why doe New work but edit/update not?

It seems rather odd but my application will happily allow me to add new records via my form, but using the same form partial the edit action seems to work fine (It throws no errors) but completely fails to change the database in any way. Do I need to add a @users.save command or something?

Here is my UsersController code

class UsersController < ApplicationController   # GET /users   # GET /users.xml   def index     if params[:usersearch].blank?     @users = User.find(:all)     else

        @users = User.find(:all, :conditions => ['Surname LIKE ? or Forename LIKE ? or Position_Group LIKE ?', "%#{params[:usersearch]}%", "%#{params[:usersearch]}%", "%#{params[:usersearch]}%"])   end

    respond_to do |format|       format.html # index.html.erb       format.xml { render :xml => @users }     end   end

  # GET /users/1   # GET /users/1.xml   def show     @user = User.find(params[:id])

    respond_to do |format|       format.html # show.html.erb       format.xml { render :xml => @user }     end   end

  # GET /users/new   # GET /users/new.xml   def new     @user = User.new

    respond_to do |format|       format.html # new.html.erb       format.xml { render :xml => @user }     end   end

  # GET /users/1/edit   def edit     @user = User.find(params[:id])   end

  # POST /users   # POST /users.xml   def create     @user = User.new(params[:user])

    respond_to do |format|       if @user.save         flash[:notice] = 'User was successfully created.'         format.html { redirect_to(@user) }         format.xml { render :xml => @user, :status => :created, :location => @user }       else         format.html { render :action => "new" }         format.xml { render :xml => @user.errors, :status => :unprocessable_entity }       end     end   end

  # PUT /users/1   # PUT /users/1.xml   def update     @user = User.find(params[:id])

    respond_to do |format|       if @user.update_attributes(params[:user])         flash[:notice] = 'User was successfully updated.'         format.html { redirect_to(@user) }         format.xml { head :ok }       else         format.html { render :action => "edit" }         format.xml { render :xml => @user.errors, :status => :unprocessable_entity }       end     end   end

  # DELETE /users/1   # DELETE /users/1.xml   def destroy     @user = User.find(params[:id])     @user.destroy

    respond_to do |format|       format.html { redirect_to(users_url) }       format.xml { head :ok }     end   end end

What does the form partial look like?

Michael Breen wrote:

What does the form partial look like?

here you go

<%= error_messages_for :user %>

<% form_for(@user) do |f| %>

<h1>Personal Details</h1>

<table>

<tr>

<td>     <b>ImageName</b><br>       <%= f.text_field :ImageName %> </td> <td>     <b>Surname</b><br>       <%= f.text_field :SurName %> </td> <td>     <b>Forename</b><br>       <%= f.text_field :ForeName %> </td>

<td>     <b>Title</b><br>       <%= f.text_field :Title %> </td>

</tr>

<tr>

<td>     <b>Room No</b><br>       <%= f.text_field :RoomNo %> </td> <td>     <b>Phone No</b><br>       <%= f.text_field :PhoneNo %> </td>

<td>     <b>EMail</b><br>       <%= f.text_field :EMail %>

</td>

</tr>

</table>

<p>     <%= f.submit "Save" %> </p>

<% end %>

Michael Breen wrote:

What does the form partial look like?

I've also noted that the destroy option doesn't delete records either.

Do I need to add a @users.save command or something?

update_attributes returns true if the save was successful.

You say that you don't get any errors but what happens when you hit save? Does it redirect to the edit or show action?

Mike Breen wrote:

You say that you don't get any errors but what happens when you hit save? Does it redirect to the edit or show action?

On Jun 4, 8:51 am, Dale Cunnigham <rails-mailing-l...@andreas-s.net>

It redirects to the show action.

hmmm...did you check the log or watch the output of script/server?

Michael Breen wrote:

hmmm...did you check the log or watch the output of script/server?

Here is the last entry the one that occurs when I click the save button.

Processing UsersController#index (for 134.225.101.126 at 2008-06-04 16:00:10) [PUT]   Session ID: random stuff   Parameters: {"user"=>{"CorrectEditedForeName"=>"", "SurName"=>"CorrectEditedTestName", PhoneNo"=>"6609", "Duties"=>"", "RoomNo"=>"1L38", "commit"=>"Save", authenticity_token"=>"random digits ive removed", "_method"=>"put", "action"=>"index", "controller"=>"users"}   e[4;36;1mUser Load (0.431220)e[0m e[0;1mSELECT * FROM `users` e[0m Rendering template within layouts/users Rendering users/index   e[4;35;1mUser Columns (0.013844)e[0m e[0mSHOW FIELDS FROM `users`e[0m Completed in 1.15826 (0 reqs/sec) | Rendering: 0.52547 (45%) | DB: 0.44506 (38%) | 200 OK [http://webaddress/users/users/\]

It seems to look ok no?

  Parameters: {"user"=>{"CorrectEditedForeName"=>"",

should be: {"user"=>{"ForeName"=>"CorrectEditedForeName",

John Yerhot wrote:

  Parameters: {"user"=>{"CorrectEditedForeName"=>"",

should be: {"user"=>{"ForeName"=>"CorrectEditedForeName",

Yep it is, my paste is not precise since I've edited it to protect the innocent :smiley:

I wouldn't have thought the error was going to be in the data.

Are your routes set up properly? What's your output from rake routes?

(I'm just going through the normal troubleshooting steps I would take
to track this down. if you don't think I'm helping please feel free to
ignore me :wink:

Michael Breen wrote:

Are your routes set up properly? What's your output from rake routes?

(I'm just going through the normal troubleshooting steps I would take to track this down. if you don't think I'm helping please feel free to ignore me :wink:

              users GET /users {:controller=>"users", :action=>"index"}     formatted_users GET /users.:format {:controller=>"users", :action=>"index"}                     POST /users {:controller=>"users", :action=>"create"}                     POST /users.:format {:controller=>"users", :action=>"create"}            new_user GET /users/new {:controller=>"users", :action=>"new"} formatted_new_user GET /users/new.:format {:controller=>"users", :action=>"new"}           edit_user GET /users/:id/edit {:controller=>"users", :action=>"edit"} formatted_edit_user GET /users/:id/edit.:format {:controller=>"users", :action=>"edit"}                user GET /users/:id {:controller=>"users", :action=>"show"}      formatted_user GET /users/:id.:format {:controller=>"users", :action=>"show"}                     PUT /users/:id {:controller=>"users", :action=>"update"}                     PUT /users/:id.:format {:controller=>"users", :action=>"update"}                     DELETE /users/:id {:controller=>"users", :action=>"destroy"}                     DELETE /users/:id.:format {:controller=>"users", :action=>"destroy"}                root / {:controller=>"users", :action=>"index"}                            /:controller/:action/:id                            /:controller/:action/:id.:format

Did this problem start when you put the form in the partial?

You could try this:

view/users/edit.html.erb

<%= error_messages_for :user %>

<% form_for(@user) do |f| %>

  <%= render :partial => 'deliverable_form', :locals => { :f => f } %>      <%# if you're using 2.1 there is a nicer way: Fundamental Tips about Coding | self. works_with_ruby?   %> <p>     <%= f.submit "Save" %> </p>

put this in view/users/_form.html.erb

<h1>Personal Details</h1>

<table>

<tr>

<td>     <b>ImageName</b><br>       <%= f.text_field :ImageName %> </td> <td>     <b>Surname</b><br>       <%= f.text_field :SurName %> </td> <td>     <b>Forename</b><br>       <%= f.text_field :ForeName %> </td>

<td>     <b>Title</b><br>       <%= f.text_field :Title %> </td>

</tr>

<tr>

<td>     <b>Room No</b><br>       <%= f.text_field :RoomNo %> </td> <td>     <b>Phone No</b><br>       <%= f.text_field :PhoneNo %> </td>

<td>     <b>EMail</b><br>       <%= f.text_field :EMail %>

</td>

</tr>

</table>

You can also check the html that is being rendered for the edit action
and make sure that the form has the right action.

You on FastCGI?

hostingrails.com has this problem when you're on FastCGI and REST.

Really?

I have 4 RESTful sites deployed to hostingrails.com all running on
FastCGI and haven't had a single issue.

John Yerhot wrote:

ive removed", "_method"=>"put", "action"=>"index",

Looks like a routing issue to me, should be calling the update action... you could try explicitly calling update and see if it works... <% form_for :user, @user, :url => { :action => "update" } do |f| %>

Ok I moved the form back into the edit and new html.erb files

and then added replaced <% form_for(@user) do |f| %> with <% form_for :user, @user, :url => { :action => "update" } do |f| %> in the the edit.html.erb file

On clicking the save button I get redirected to the url

http://www.website.com/users/users/1221

and get the following error

Unknown action

No action responded to 1221

I guess I need to do something with routing for the edit action.

I was trying to stick with just using

ActionController::Routing::Routes.draw do |map|   map.resources :users   map.root :controller => "users"   map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format' end

try sticking with <% form_for(@user) do |f| %>

Michael Breen wrote:

try sticking with <% form_for(@user) do |f| %>

If I go with that I'm back to the original problem. No errors and it just doesn't write changes to the database.

The Logfile has the following entries for the attempted edit...

Processing UsersController#edit (for IPADDRESS at 2008-06-05 13:31:58) [GET]   Session ID: BAh7BzoMY3NyZl9pZCIlM2RkOTljMTk3YzE2MWQwMTY3MTNhN2NlZTc5OTFm%0ANWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D--92ba3187f08e3b00058aa442cdf467c0efde5102   Parameters: {"action"=>"edit", "id"=>"1222", "controller"=>"users"}   e[4;36;1mUser Columns (0.013465)e[0m e[0;1mSHOW FIELDS FROM `users`e[0m   e[4;35;1mUser Load (0.011432)e[0m e[0mSELECT * FROM `users` WHERE (`users`.`id` = '1222') e[0m Rendering template within layouts/users Rendering users/edit Completed in 0.10657 (9 reqs/sec) | Rendering: 0.05074 (47%) | DB: 0.02490 (23%) | 200 OK [http://www.met.rdg.ac.uk/users/users/1222/edit\]

Processing UsersController#index (for IPADDRESS at 2008-06-05 13:32:04) [PUT]   Session ID: BAh7BzoMY3NyZl9pZCIlM2RkOTljMTk3YzE2MWQwMTY3MTNhN2NlZTc5OTFm%0ANWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D--92ba3187f08e3b00058aa442cdf467c0efde5102   Parameters: {"user"=>{"SurName"=>"test 3", "Title"=>"Mr", "EMail"=>"tester@gimpland.co.uk", "ForeName"=>"Donny", "RoomNo"=>"3F546"}, "commit"=>"Save", "authenticity_token"=>"tokendigits", "_method"=>"put", "action"=>"index", "controller"=>"users"}   e[4;36;1mUser Load (0.280259)e[0m e[0;1mSELECT * FROM `users` e[0m Rendering template within layouts/users Rendering users/index   e[4;35;1mUser Columns (0.013465)e[0m e[0mSHOW FIELDS FROM `users`e[0m Completed in 0.99386 (1 reqs/sec) | Rendering: 0.51505 (51%) | DB: 0.29372 (29%) | 200 OK [http://www.website.com/users/users/\]