Help a n00b?


#1

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)

<%= render_collection_of_partials "list_stripes", @foods %> <%= form_remote_tag( :html => {'id' => 'createFoodForm'}, :url => {:action => 'create_with_ajax'}, :update => 'foodList', :position => 'bottom', :complete => '$ (createFoodForm).reset();' ) %> <%= text_field 'food', 'name' , "size"=>20 % > <%= text_field 'food', 'serving' , "size"=>5 % > <%= text_field 'food', 'units' , "size"=>10 % > <%= text_field 'food', 'calories', "size"=>5 % > <%= text_field 'food', 'fat' , "size"=>5 % > <%= text_field 'food', 'sat_fat' , "size"=>5 % > <%= text_field 'food', 'sodium' , "size"=>5 % > <%= text_field 'food', 'carbs' , "size"=>5 % > <%= text_field 'food', 'fiber' , "size"=>5 % > <%= text_field 'food', 'sugars' , "size"=>5 % > <%= text_field 'food', 'protein' , "size"=>5 % > <%= submit_tag "Add" %>

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!


#2

Updated code, see below:

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

> <%= text_field 'food', 'sodium' , "size"=>5 %

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!