remote_form_for in index.html.erb file not working w/ AJAX...Ruby on Rails...

Posted by bgadoci on Stack Overflow See other posts from Stack Overflow or by bgadoci
Published on 2010-05-09T05:39:24Z Indexed on 2010/05/09 5:48 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

Just curious if I am overlooking something simple here. I have deployed the remote_form_for in the show.html.erb code before to render comments on a post (project in this case) without a problem. I have moved this code to the index view and seems to degrade to the normal form_for action (page refresh). I am not getting any javascript errors so not sure what is wrong here. Here is my code:

index.html.erb

<% remote_form_for [project, Comment.new] do |f| %>

    <p>
        <%= f.label :body, "New Comment" %><br/>
        <%= f.text_area (:body, :class => "textarea") %>
    </p>
    <p>
        <%= f.label :name, "Name" %> (Required)<br/>
        <%= f.text_field (:name, :class => "textfield") %>
    </p>
    <p>
        <%= f.label :email, "Email" %> (Required but will not be displayed)<br/>
        <%= f.text_field (:email, :class => "textfield") %>
    </p>
    <p><%= f.submit "Add Comment" %></p>
<% end %>

CommentsController#create

   def create
     @project = Project.find(params[:project_id])
     @comment = @project.comments.create!(params[:comment])

     respond_to do |format|

         format.html { redirect_to projects_path }
         format.js
   end
  end

/views/comments/create.js.rjs

page.insert_html :bottom, :commentwrapper, :partial => @comment
page[@comment].visual_effect :highlight 
page[:new_comment].reset
page.replace_html :notice, flash[:notice]
flash.discard

/views/comments/_comment.html.erb

<% div_for comment do %>

        <div id="commentwrapper">
        <%  if admin? %>
        <%=link_to_remote "X", :url => [@project, comment], :method => :delete %>
        <% end %>
        <%= h(comment.body) %><br/><br/>
        Posted <%= time_ago_in_words(comment.created_at) %> ago by <%= h(comment.name) %> 
        <%  if admin? %>
         | <%= h(comment.email) %>

        <% end %></div>


<% end %>

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby