为什么 simple_form 不创建我的字段并创建隐藏字段?
这是我的 ruby 代码:
<%= simple_form_for([@video, @video.comments.new]) do |f| %>
<% f.association :comment_title %>
<% f.input :body %>
<% f.button :submit %>
<% end %>
这是生成的 HTML 标记:
<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>
显然它没有正确创建 :body 输入字段和关联选择列表。这是为什么?我该如何解决它?
顺便说一句,一个视频有很多评论,一条评论属于视频。另外,一个comment_title有很多条评论,一条评论属于一个视频。 Comment_title 是使用虚拟属性生成的。
如果您想查看任何其他代码,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这两个都是因为您的 Rails 应用程序中的选择。第一个是您已选择将应用程序配置为使用 utf8 进行字符编码。第二个是因为默认情况下,应用程序设置为防止跨站点请求伪造攻击。真实性令牌确保当用户提交表单时返回到服务器的响应实际上来自您,而不是其他只是监视您的流量并发布信息来扰乱您的数据库的来源。
Both of these are because of choices in your rails application. The first is that you have selected to configure the application to use utf8 for character encoding. The second is because by default the application is setup to protect against cross site request forgery attacks. The authenticity token ensures that the response coming back to the server when the user submits the form is actually from you and not some other source just watching your traffic and posting away to mess with your database.
好吧,问题是我需要在表单元素中添加“=”到 <%= 。
Ok so the problem was that I needed to add the "=" to <%= in my form elements.