取消选中完整时间框后单击更新时,我得到以下信息。如果我注释掉复选框,它不会发生,但如果我用单选按钮替换相同的东西。
用户中的 NoMethodError#update
显示第 26 行出现的 app/views/users/_form.erb:
当你没想到时,你有一个 nil 对象!您可能期望有一个 Array 的实例。评估 nil.map 时发生错误
提取的源代码(大约第 26 行):
23: <p>
24: <%= form.label :manager %>
25: <%#= collection_select( :user , :manager_id, @managers, :id, :full_name, {},{}) %>
26: <%= form.collection_select(:manager_id, @managers, :id, :full_name, {},{}) %>
27: </p>
28: <p>
29: <%= form.label :groups %>
完整的来源
模板:
<% form_for @user, :url => user_path(@user) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
<%= f.submit "Update" %>
<% end %>
部分的:
<p>
<%= form.label :login %><br />
<%= form.text_field :login %>
</p>
<p>
<%= form.label :first_name %><br />
<%= form.text_field :first_name %>
</p>
<p>
<%= form.label :last_name %><br />
<%= form.text_field :last_name %>
</p>
<p>
<%= form.label :rate %><br />
<%= form.text_field :rate %>
</p>
<p>
<%= form.label :full_time %><br />
<%= form.check_box :full_time %>
</p>
<p>
<%= form.label :manager %>
<%#= collection_select( :user , :manager_id, @managers, :id, :full_name, {},{}) %>
<%= form.collection_select(:manager_id, @managers, :id, :full_name, {},{}) %>
</p>
<p>
<%= form.label :groups %>
<%= form.collection_select(:group_ids, @groups, :id, :name, {}, {:multiple => true, :size => 15}) %>
</p>
然后是我的控制器
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
def new
@user = User.new
@managers = Group.find_by_name('management').users
@groups = Group.all
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])
@managers = Group.find_by_name('management').users
@groups = Group.all
end