views:

45

answers:

1

I am stuck; I did a search and I can't find a pointer on how to get this project to work. I have a form on my index.html.erb as:

<html>   <head>
    <title>Ajax List Demo</title>   <h1>Listing posts</h1> 

    <%= javascript_include_tag "prototype" %>   </head>   <body>
    <h3>Add to list using Ajax</h3>
    <% form_tag (  :remote=>true, :update => 'my_list', :action => :list , :method=>:post, :format =>:xml ) do %>

      Enter the url:
      <%= text_field_tag 'url' ,'', :size => 80 %>
      <%= submit_tag "Find" %>
    <% end %>
    <div id="my_list"><%= render :partial => 'profiles/list' %></div>   </body> </html>

Now I have a div with this called my_list. When I submit the form I want my partial _list.html.erb (inside profiles dir, tried home dir too) to update with the results of list.

My home controller has this method:

def list
    puts "here!!!!"
   reader = Reader.new
  @profiles =  reader.processURL(params[:url])
    render :partial=>'profiles/list', :locals => { :profiles => @profiles}
end

I end up getting this error:

ActionView::MissingTemplate (Missing partial profiles/list with {:locale=>[:en, :en], :handlers=>[:rjs, :builder, :rhtml, :rxml, :
erb], :formats=>[:xml]} in view paths "C:/Users/....tree/app/views"):
  app/controllers/home_controller.rb:22:in `list'

Rendered C:/Ruby187/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/missing_template.erb
within rescues/layout (1.0ms)

Could anyone help me or send me in the right direction to understand how to update a div rendering via Rails on form submit? Thanks again.

A: 

Kunal First of all I am getting ajax to render(@homepages) in index.html.erb via index.js.erb OK, but my search to update @homepages is not working.

I am not sure if what I am saying to you is correct, but knowing what I have done and coming up with errors similar to yours I offer the following.

In your javascript_include_tag you missed out rails.js which I think handles the ajax request. javascript_include_tag defaults would have done all that for you plus some others that you do not need. Providing you are not using jquery you need prototype and rails.js as a minimum.

I do not think the format of this form_tag is correct:-

<% form_tag ( :remote=>true, :update => 'my_list', :action => :list , :method=>:post, :format =>:xml ) do %>

The first value after the "( "should be the item_path I think. then the conditions. :action => :list , I think.

Method => post should take you to the create or new action.

The

:update => 'my_list', would be done in the list.js.erb using javascript (prototype) The code for jquery and prototype is similar, but slightly different (see Railscast 205)

Why format xml in the form_tag, put it in the controller "list" mine is:- respond_to do |format| format.html # index.html.erb format.xml { render :xml => @homepages } format.js

end

Don't sure if you can get away with 'url' should not it be :url you might be able to use either.

When I was getting the missing template it was because it was looking for a search.html.erb file in your case it is looking for a list.html. erb this is html searching.

I will post this on your link perhaps other "in the know" developers will correct me.

Perhaps you might like to post my previous email. Don.

MDM