0

This is my ruby code:

<%= simple_form_for([@video, @video.comments.new]) do |f| %>
  <% f.association :comment_title %>
  <% f.input :body %>
  <% f.button :submit %>
<% end %>

This is the generated HTML markup:

<form accept-charset="UTF-8" action="/videos/485/comments" class="simple_form comment" id="new_comment" method="post">
    <div style="margin:0;padding:0;display:inline">
        <input name="utf8" type="hidden" value="✓">
        <input name="authenticity_token" type="hidden" value="55xSU8JUe1SgipjAkAEvCvidFdJY3hv8Qz5VBqUSrdE=">
    </div>
    <input class="button" id="comment_submit" name="commit" type="submit" value="Create Comment">
</form>

Obviously it's not creating the :body input field and the association select list correctly. Why is this and how can I fix it?

Btw, a video has many comments, and a comment belongs to video. Also, a comment_title has many comments, and a comment belongs to a video. Comment_title is generated with virtual attributes.

Please let me know if there is any other code you would like to see.

4

2 回答 2

3

这两者都是因为您在 Rails 应用程序中的选择。首先是您已选择将应用程序配置为使用 utf8 进行字符编码。第二个是因为默认情况下应用程序设置为防止跨站点请求伪造攻击。真实性令牌确保当用户提交表单时返回到服务器的响应实际上来自您,而不是其他一些来源,只是监视您的流量并发布以弄乱您的数据库。

于 2011-04-05T04:30:50.273 回答
2

好的,问题是我需要在表单元素中将“=”添加到 <%=。

于 2011-04-06T02:43:03.247 回答