Topic: nil object error

i am new to rails ...need help
need to submit a nested form but getthe following error ...


You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[ ]


VIEW :

<h2 align="right"><%= Time.now %></h2>
<h1><u>Listing Users</h1></u>
<br></br><table>
<td><%form_for(:ledger, :controller=>"ledger",:action=>"create") do |f|%></td>
<tr><% for @user in @users %></tr>
<td><strong><%= @user.user_name %></td></strong>
<td><%= f.hidden_field "#{@user.id}", :value => "#{@user.id}" %></td> 
<td>AMOUNT:<%= f.text_field :amount %></td></tr>

</br>
<% end %>
</br>
<tr><td><%= f.submit "Save"  %></td></tr>
<% end %>
</table>


Controller :create

def create
    @ledger = Ledger.new(params[:ledger])
#@group=Group.find(:all)
    #@user = User.find(:all)
    logger.info"**************************"+params[:ledger].inspect
    respond_to do |format|
      if @ledger.save
        flash[:notice] = 'Ledger was successfully created.'
        format.html { redirect_to(@ledger) }
        format.xml  { render :xml => @ledger, :status => :created, :location => @ledger }
      else   
        format.html { render :action => "show" }
        format.xml  { render :xml => @ledger.errors, :status => :unprocessable_entity }
      end
    end
  end


controller : show_user

def show_user
@ledger=Ledger.new
logger.info"**************************"+params[:ledger].inspect
      @group=Group.find(params[:group][:group_id])
      @users = @group.users
      respond_to do |format|
      format.html # new.html.erb
      end#end of method
    end

model :ledger

class Ledger < ActiveRecord::Base
has_and_belongs_to_many :users

validates_presence_of :amount
serialize :ledger, Hash
end

Last edited by sudhirsb (2010-03-27 01:46:44)