- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习在 Rails 中使用嵌套资源。为了保持简单和可重现性,我设置了一个非常简单的博客应用程序,其中包含两个资源 posts
和 comments
。大部分代码都是由脚手架生成的。
我已成功修改 post#show
以在每个帖子下方显示 comments
,Add New Comment
的链接也呈现 新的评论
形式。但是我无法保存评论并收到路由错误:
ActionController::RoutingError (No route matches [POST] "/posts/1/comments/new"
评论部分形式比较
原始/嵌套资源之前:
<%= form_with(model: comment, local: true) do |form| %>
修改/嵌套资源后:
<%= form_with(url: new_post_comment_path,
scope: :comment, local: true) do |form| %>
我已将代码推送到 github repo ,具有不带嵌套资源的单独分支 master
和带嵌套资源的 nestedRoutes
。将感谢社区的帮助。
注意:Nested Resources w/ Rails 5.1 form_with 的答案对我不起作用。
最佳答案
看起来您传递的 url 是 new_post_comment_path
,当您可能希望您的表单进入创建路径时。根据您的路线,我假设这看起来像 post_comments_path
。
这就是您看到错误的原因,没有为 new
路径定义 POST 方法(仅 GET)。
关于ruby-on-rails - 在rails中使用嵌套资源时如何修改form_with,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47496836/
我正在尝试将隐藏字段添加到 form_with。 这里有 3 次尝试(和结果/错误信息) 第一次尝试 发件人:https://guides.rubyonrails.org/form_helpers.h
我正在重构我的应用程序的路由以解决 rule of thumb因为我的路线很长。 假设我有以下模型 class Company < ApplicationRecord has_many :proj
早上好。 我正在学习教程 http://edgeguides.rubyonrails.org/getting_started.html我发现以下内容: 我有一个名为 ArticlesControlle
我收到错误: undefined form_with for #:0x551e5a8> in articles#new 错误发生在以下文件中:new.html.erb其中有:
我正在使用 form_with helper 创建一个新表单,正如您所知,正在检测您是否位于新记录页面或编辑页面([遵循 Rails 指南中的 CRUD 示例][1],我将表单渲染为重用表单的一部分)
我正在尝试使用最新的 form_with 发送 Ajax 帖子。 这就是我所做的。 jQuery(document).ready(function($) { $('#co
我的应用程序中有一个表单,我通过以下方式声明它: = form_with model: project, remote: true, method: :put do |f| = f.select
Rails 的新手,正在尝试弄清楚如何将参数从 View 传递到表单,然后再传递到 Controller ,或者最有可能的是,找到一种为新对象分配外键的更好方法。我有一个链接到特定 socket 对象
对于以下内容,如何将 form_for 转换为 form_with: 我查看了 Rails 的 form_with 文档,但没有找到任何相关示例。 谢谢! 最佳答案 form_with 具有 sco
对于以下内容,如何将 form_for 转换为 form_with: 我查看了 Rails 的 form_with 文档,但没有找到任何相关示例。 谢谢! 最佳答案 form_with 具有 sco
我尝试了 form_tag 和 form_with - 结果是一样的, Controller 的 Action 永远不会被触发。 # routes.rb resources :products do
背景 在我的应用程序中,系列 由许多书籍 组成。系列的显示页面允许用户查看系列中的所有书籍并使用表单向系列中添加新书。 显示 页面上列出的每本书都有指向该书的编辑 页面的链接。编辑页面包含用于最初添加
我正在使用名为 jquery-minicolors-rails 的 gem 创建一个 rgb 表。然而,github 只显示了 simple_form_for 的例子。我正在使用 form_with。
Rails 5 引入了新的表单辅助方法 form_with . 和form_for有什么区别什么时候使用更合适? 最佳答案 这真的是为 Rails 5.1 做准备,其中只有 form_with应该使用
使用 rails5 的 form_with,我想通过单击 GET 按钮来显示当前时间文本。但是文字没有更新。 虽然我按下了按钮, 文字未更新。 响应文本已更新。 users_controller.rb
每 this pull request我可以看到一个数组应该传递给 form_with的模型参数。但是,当我提供以下内容时: ... Rails 将返回 - ActionView::Templ
我用这个把我的头发扯掉了。我在带有嵌套资源的 form_with 上得到了一个未经许可的参数。我正在使用 Rails 5.2.1 和 Ruby 2.5。 我不确定我到底哪里出了问题。我尝试了 site
我正在尝试呈现表单并将 url 和方法传递给它 home/index.html.erb 游乐设施/_form.html.erb 错误: undefined local variable or me
我刚刚从 Rails 5.1 升级到 5.2。我对已投入生产几个月没有问题的应用进行了良好的测试覆盖。 我在 Rails 5.1 中使用 form_with 几个月了。 form_with 的默认设置
Rails 5.1.2: 我正在尝试使用 form_with 创建 AJAX 表单符合Rails documentation和 this GitHub thread . 这段代码: 事实上这段代码
我是一名优秀的程序员,十分优秀!