Forum: Ruby on Rails Help a n00b?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
David Olbersen (Guest)
on 2006-02-24 03:24
(Received via mailing list)
So I'm trying to do that hot new thing with AJAXy forms:

http://idiet.toasterwaffles.com/foods/list

Here's the relevant code in list.rhtml (for the form portion)

   <tbody>
   <%= render_collection_of_partials "list_stripes", @foods %>
   </tbody>

   <tfoot>
   <tr id="addFood"><%= form_remote_tag( :html => {'id' =>
'createFoodForm'},
                                         :url => {:action =>
'create_with_ajax'},
                                         :update => 'foodList',
                                         :position => 'bottom',
                                         :complete => '$
(createFoodForm).reset();'
                                       ) %>
     <td class="txt"><%= text_field 'food', 'name'    , "size"=>20  %
 ></td>
     <td class="num"><%= text_field 'food', 'serving' , "size"=>5   %
 ></td>
     <td class="txt"><%= text_field 'food', 'units'   , "size"=>10  %
 ></td>
     <td class="num"><%= text_field 'food', 'calories', "size"=>5   %
 ></td>
     <td class="num"><%= text_field 'food', 'fat'     , "size"=>5   %
 ></td>
     <td class="num"><%= text_field 'food', 'sat_fat' , "size"=>5   %
 ></td>
     <td class="num"><%= text_field 'food', 'sodium'  , "size"=>5   %
 ></td>
     <td class="num"><%= text_field 'food', 'carbs'   , "size"=>5   %
 ></td>
     <td class="num"><%= text_field 'food', 'fiber'   , "size"=>5   %
 ></td>
     <td class="num"><%= text_field 'food', 'sugars'  , "size"=>5   %
 ></td>
     <td class="num"><%= text_field 'food', 'protein' , "size"=>5   %
 ></td>
     <td><%= submit_tag "Add" %></td>
   </tr>
   </tfoot>

and here's the relevant code in foods_controller.rb

     def create_with_ajax
         @food = Food.new(params[:food])
         if @food.save
             render_partial "list_stripes"
         end
     end

I've got a _list_stripes.rhtml partial that creates the table. The
crazy part is that when I try creating a new item I get "Template is
missing" -- which I don't understand at all. If I change the action
in form_remote_tag to the default 'create' method I get back (in the
table) an empty form, as if nothing had been passed in yet.

Any ideas where I messed up? Thanks for reading this far!
David Olbersen (Guest)
on 2006-02-24 03:40
(Received via mailing list)
Updated code, see below:

On Feb 23, 2006, at 5:21 PM, David Olbersen wrote:

>   <tfoot>
> ></td>
>     <td class="num"><%= text_field 'food', 'sodium'  , "size"=>5   %
>   </tr>
>   </tfoot>
>
> and here's the relevant code in foods_controller.rb
>
>     def create_with_ajax
>         @food = Food.new(params[:food])
>         if @food.save
>             render_partial "list_stripes"
else
   render_text "Couldn't create!"
>         end
>     end
>

Now I get "Couldn't create" all over the place!
This topic is locked and can not be replied to.