Question

I am using rails 4 to design this blog containing articles comments and users everything

works great only i want to list the articles in the index page and their comments underneath

with an ajax comment form under each article(to create new articles via javascript) my code

shows no error but the form as refused to show up maybe something am doing wrong. will

paste

all code so i can be corrected...

my index.html.erb

<h1>Articles</h1>

<% @articles.each do |article| %>

    <%= render :partial => article %>
    <%= render :partial => article.comments %>

    <% form_for ([article, Comment.new],:remote => true) do |f| %>
    <p>
    <%= f.label :content, "New Comment" %><br/>
    <%= f.text_area :content %>
    </p>
    <p><%= f.submit "Add Comment"%></p>
  <% end %>
<% end %>

<p><%= link_to "New Article", new_article_path %></p>

the first partial code <%= render :partial => article %>

<h2><%= link_to article.name, article %></h2>

the second partial <%= render :partial => article.comments %>

  <%= div_for comment do %>
  <p><strong> <%= comment.user.username %> says</strong></p>
  <%= simple_format comment.content %>

  <% end %>

the code above doesn't throw any error but the form as refused to show up any help please

or is there a better way of doing it ?

Was it helpful?

Solution

Replace

<% form_for ([article, Comment.new],:remote => true) do |f| %>

with

<%= form_for ([article, Comment.new],:remote => true) do |f| %>

Missing = sign which tells ERB to evaluate and display the result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top