Question

i get the following when i click update after unchecking the full time box. If i Comment out the check box it doesn't happen, but if i replace with a radio button same thing.

NoMethodError in Users#update

Showing app/views/users/_form.erb where line #26 raised:

You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.map

Extracted source (around line #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 %>

the full source

template:

<% form_for @user, :url => user_path(@user) do |f| %>
  <%= f.error_messages %>
  <%= render :partial => "form", :object => f %>
  <%= f.submit "Update" %>
<% end %>

partial:

   <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>

and then my controller

 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
Was it helpful?

Solution

had to do with validation at the model level on the full_time attribute

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top