After much ado about the naming of model adn controllers...
model : Expense controller : Expenses route : map.resources :expenses
Here I am using mysql database and created a unique index, since db:migrated created an id object and made it as primary key. Now in the def create @expense = Expense.new(params[:expense]) if @expense.save flash[:viola] = 'New expense saved.. be frugal, save during this bad economy' redirect_to expenses_path else render :action => 'new' #redirect_to new_expense_path end
Here I try to save, and if any error, render action =>'new'. When I do that I get the
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
Extracted source (around line #1):
1: <% form_for @e1 do |er| %> 2: <p> 3: name :<br /> 4: <%= er.text_field :name %>
I have the @e1 defined correctly in the controller (how can it work when I go to the new page directly using localhost:300/expenses/new ).
And the trace : vendor/rails/actionpack/lib/action_controller/record_identifier.rb: 72:in `dom_id' vendor/rails/actionpack/lib/action_view/helpers/ record_identification_helper.rb:16:in `dom_id' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:264:in `apply_form_for_options!' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:248:in `form_for' app/views/expenses/new.html.erb:1:in `_run_erb_47app47views47expenses47new46html46erb' app/controllers/expenses_controller.rb:18:in `create'
What I don't understand is the form_for works fine when used initially, or even through the redirect_to new_expense_path but not through the action => 'new'
Any help is appreciated......