当前位置: 首页 > 知识库问答 >
问题:

编辑表单没有匹配[POST]的路由-Ruby on rails

糜单弓
2023-03-14

即时消息使用rails 5

我有一个叫普莱斯的模型。(有许多产品)

Prices有一个名为Product的模型(属于price)

在这种情况下,我可以创建新产品,也可以销毁产品。

我的路线

  resources :prices do
    resources :products
  end

在我的价格秀里

<%= link_to "Edit", edit_price_product_path(product.price, product) %>

在我的产品编辑中

<%= form_for @product, :url => {:action => :edit}, :method => :post do |f| %>
    <%= f.text_field :name, placeholder: 'Name' %>
    <%= f.submit %>
<% end %>

在我的产品控制器中

def edit
end

def update
    product.update(product_params)
    if @product.update(product_params)
        redirect_to price_path(@price)
    else
        render 'edit'
    end
end

我的耙路线

price_products GET    /prices/:price_id/products(.:format)          products#index
                         POST   /prices/:price_id/products(.:format)          products#create
     new_price_product GET    /prices/:price_id/products/new(.:format)      products#new
    edit_price_product GET    /prices/:price_id/products/:id/edit(.:format) products#edit
         price_product GET    /prices/:price_id/products/:id(.:format)      products#show
                         PATCH  /prices/:price_id/products/:id(.:format)      products#update
                         PUT    /prices/:price_id/products/:id(.:format)      products#update
                         DELETE /prices/:price_id/products/:id(.:format)      products#destroy

问题是

当我点击提交按钮时,我发现了这个错误

No route matches [POST] "/price/price_id/product/product_id/edit"

谢谢你帮我

共有1个答案

赫连永怡
2023-03-14

您可以使用命名空间语法来处理嵌套资源:

<%= form_for [:price, @product] do |f| %>
  <%= f.text_field :name, placeholder: 'Name' %>
  <%= f.submit %>
<% end %>
 类似资料:
  • Tango支持4种形式的路由匹配规则 静态路由 tg.Get("/", new(Action)) tg.Get("/static", new(Action))匹配 URL:/ 到 Action结构体的Get函数 匹配 URL:/static 到 Action结构体的Get函数 命名路由 tg.Get("/:name", new(Action)) tg.Get("/(:name)", new(Act

  • 我是刚来香港的,所以请容忍我:)我在windows服务器上作为主机托管我的APIhttp://supermarket.xxxx.com:5000 在Ubuntu盒上添加了如下服务(http://supermarket.xxxx.com已添加到主机文件中) HTTP/1.1 201创建日期: Thu,17 Dec2020 07:11:50GMT Content-Type: Application/j

  • 我正试图实现本教程所示的acts\u as\u votable gem https://www.youtube.com/watch?v=7-1HCWbu7iU 似乎一切正常,除了单击upvote或downvote时,出现以下错误: 这是支持/反对票功能的代码 这就是路线。rb文件: 以下是links\u controller中的upvote和downvote操作 有没有办法解决这个问题?

  • 注意:本部分是为v1 API编写的,但这些概念也适用于v2 API。它将在未来版本的v2 API中重新描述。 Envoy的路由匹配过程如下: HTTP请求的头域字段 host 或 :authority 与虚拟主机匹配。 按顺序检查虚拟主机中的每个路由表。如果匹配,则使用该路由并且不再匹配路由。 独立地,依次检查虚拟主机中的每个虚拟集群。如果匹配,则使用虚拟群集,不再进一步匹配集群。 返回 上一级

  • 我有两个感兴趣的文件:build。靴子 和src/clj/vidiot/server。clj 然后我,, 然后在我的浏览器中转到localhost:9090,终端打印。 我可以通过降级来解决这个问题:构建中的依赖项。引导至。 所以,我的问题是,为什么我不能在构建uberjar时使用(本文中的最新版本)?

  • 路由拥有三个属性来决定是否“匹配“一个 URL: 嵌套关系 和 它的 路径语法 它的 优先级 嵌套关系 React Router 使用路由嵌套的概念来让你定义 view 的嵌套集合,当一个给定的 URL 被调用时,整个集合中(命中的部分)都会被渲染。嵌套路由被描述成一种树形结构。React Router 会深度优先遍历整个路由配置来寻找一个与给定的 URL 相匹配的路由。 路径语法 路由路径是匹配