我试过
= form_for [@user, @subscription], html: {id: 'subscription_form'} do |f|
(ActionController :: UnknownFormat)和
= form_for @subscription, html: {id: 'subscription_form'} do |f|
(未定义的方法`subscription_path')但它不起作用。但这很有效:
= form_for @subscription, url: user_subscription_path(@user), html: {id: 'subscription_form'} do |f|
我的路线:
resources :users do
resource :subscription, only: [:edit, :new, :create, :update, :destroy]
和
C:\Users\Chloe\workspace\>rake routes | grep subscription
new_user_subscription GET /users/:user_id/subscription/new(.:format) subscriptions#new
edit_user_subscription GET /users/:user_id/subscription/edit(.:format) subscriptions#edit
user_subscription PATCH /users/:user_id/subscription(.:format) subscriptions#update
PUT /users/:user_id/subscription(.:format) subscriptions#update
DELETE /users/:user_id/subscription(.:format) subscriptions#destroy
POST /users/:user_id/subscription(.:format) subscriptions#create
user.rb
class User < ApplicationRecord
has_one :subscription
我在这种情况的文档中没有看到任何内容:http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for