Forum: Ruby on Rails Update incorrect when using multiple table

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.
7c8f8b6eae4dd991e3a9065c68451361?d=identicon&s=25 Wai Tsang (sneptune)
on 2007-02-05 18:18
Hi,

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])
  end

  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
    else
      render :action => 'edit'
    end
  end

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?
7c8f8b6eae4dd991e3a9065c68451361?d=identicon&s=25 Wai Tsang (sneptune)
on 2007-02-05 19: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.