首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在文章索引页rails 4中显示注释表单

如何在文章索引页rails 4中显示注释表单
EN

Stack Overflow用户
提问于 2014-03-10 21:50:23
回答 1查看 2.5K关注 0票数 0

我正在使用rails 4来设计这个包含articlescommentsusers的博客。

非常好,我只想在索引页面中列出文章及其下面的注释。

在每篇文章下使用ajax注释表单(通过javascript创建新文章),我的代码

显示没有错误,但是拒绝出现的表单可能是做错了什么。将要

粘贴

所有密码这样我才能被纠正..。

我的index.html.erb

代码语言:javascript
复制
<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>

第一个部分代码<%=呈现:分部=>文章%>

代码语言:javascript
复制
<h2><%= link_to article.name, article %></h2>

第二部分<%=呈现:部分=> article.comments %>

代码语言:javascript
复制
  <%= div_for comment do %>
  <p><strong> <%= comment.user.username %> says</strong></p>
  <%= simple_format comment.content %>

  <% end %>

上面的代码没有抛出任何错误,但是表单拒绝显示任何帮助。

还是有更好的方法去做呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-10 21:56:11

替换

代码语言:javascript
复制
<% form_for ([article, Comment.new],:remote => true) do |f| %>

使用

代码语言:javascript
复制
<%= form_for ([article, Comment.new],:remote => true) do |f| %>

缺少=标志,通知再培训局评估和显示结果。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22312085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档