That worked, care to explain the theory behind it, or some links how this
routing works???

On Wed, Nov 18, 2009 at 6:25 PM, Artem Korolev <[email protected]> wrote:

> Replace
> @expense = Expense.new(params [: expense])
> at
> @e1 = Expense.new(params [: expense])
> in the create action
> since the render =>: new variable @e1 is not defined, but in view, it is
> used.
>
> 2009/11/18 Arun Srini <[email protected]>
> >
> > 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......
> >
> > --
> >
> > You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> > For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=.
> >
> >
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=.
>
>
>


-- 
If opportunity doesn't knock, build a door. - Milton Berle

http://www.twitter.com/arzvi
http://delicious.com/arzvi

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=.


Reply via email to