Forum: Ruby on Rails Update incorrect when using multiple table

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Wai T. (Guest)
on 2007-02-05 19:18

I used scaffold to generate the basic structure for the application.
The application has two table like this:

| ID | UserName | ServerID |
|  1 | AAA      |   1      |
|  2 | BBB      |   1      |

| ServerID | Name | Application |
|     1    |  A   |    CCC      |

In _form.rhtml, I have a select drop down box that would display the
server name instead of serverID to let user to choose from.

<%= collection_select :user, :serverid, Server.find(:all), :id,
:application %>

There is no problem when I tried to create a new user, but when I tried
to update user BBB, it would complain "Can't find Server with ID=2".

Here's my new.rhtml
<%= start_form_tag :action => 'create' %>
  <%= render :partial => 'form' %>
  <%= submit_tag "create" %>
<%= end_form_tag %>

Here's my edit.rhtml
<%= start_form_tag :action => 'update', :id => @deploy %>
  <%= render :partial => 'form' %>
  <%= submit_tag 'update' %>
<%= end_form_tag %>

Here's my users_controller.rb
  def edit
    @user = User.find(params[:id])

  def update
    @user = User.find(params[:id])
    if @user.update_attributes(params[:user])
      flash[:notice] = 'User was successfully updated.'
      redirect_to :action => 'show', :id => @user
      render :action => 'edit'

It does not make sense that it can create fine, but failed to update
using the same _form.  Does anyone have any idea or way to troubleshoot
this problem?
Wai T. (Guest)
on 2007-02-05 20:25
Nevermind.  It turns out the error is from the 'show' action.  It runs
fine now.
This topic is locked and can not be replied to.