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?