这可能没有意义,但我正在努力学习更难的东西和进步,似乎我错过了地址ID,但似乎无法找到解决方案。
我在form_for中包含了url,因为当我删除它时,应用程序会中断。但似乎我预定了网址而非编辑休息。
<%= form_for([@address.user, @address], :url => user_addresses_path) do |f| %>
错误读数:
没有路由匹配[PATCH]“/ users / 1 / addresses”
当我删除:url =&gt;
未定义的方法`user_client_address_path'
的routes.rb
Rails.application.routes.draw do
# Security Devise Setup
devise_for :admins
devise_for :users
# Main Pages
root 'website/page#index'
# Client Sections
resources :users do
scope module: "client" do
root :to => 'dashboard#index'
resources :addresses
end
end
namespace :admin do
root :to => 'panel#index'
end
end
rake路由部分输出(如果需要更多,请告诉我)
user_addresses GET /users/:user_id/addresses(.:format) client/addresses#index
POST /users/:user_id/addresses(.:format) client/addresses#create
new_user_address GET /users/:user_id/addresses/new(.:format) client/addresses#new
edit_user_address GET /users/:user_id/addresses/:id/edit(.:format) client/addresses#edit
user_address GET /users/:user_id/addresses/:id(.:format) client/addresses#show
PATCH /users/:user_id/addresses/:id(.:format) client/addresses#update
PUT /users/:user_id/addresses/:id(.:format) client/addresses#update
DELETE /users/:user_id/addresses/:id(.:format) client/addresses#destroy
答案 0 :(得分:1)
如果您使用AJAX提交表单,请尝试向其添加method: 'POST'
。
如果您要正常提交表单,请尝试将method: :post
添加到form_for
哈希。
它最终应该是:
<%= form_for([@address.user, @address], url: user_addresses_path, method: :post) do |f| %>