无法创建基于模型的表单 rails 4
Unable to create model based forms rails 4
我有基于模型的表单:
<h2>Add New Credit Card</h2>
<%= form_for @credit_card do |f| %>
some fields
<% end %>
路线:
resources :credit_card
credit_card_index GET /credit_card(.:format) credit_card#index
POST /credit_card(.:format) credit_card#create
new_credit_card GET /credit_card/new(.:format) credit_card#new
edit_credit_card GET /credit_card/:id/edit(.:format) credit_card#edit
credit_card GET /credit_card/:id(.:format) credit_card#show
PATCH /credit_card/:id(.:format) credit_card#update
PUT /credit_card/:id(.:format) credit_card#update
DELETE /credit_card/:id(.:format) credit_card#destroy
控制器:
def new
@credit_card = CreditCard.new
end
当我尝试按表单呈现时,它说:
undefined method `credit_cards_path' for #<#<Class:0x00000004c37680>:0x00000004c34570>
Did you mean? credit_card_path
credit_card_index_path
credit_card_url
它是基于模型的形式,目前我没有模型。我只想渲染和提交将去创建方法
在您的路线中,resources
定义使用复数形式。
resources :credit_cards
这将生成您的路线
credit_cards GET /credit_cards/:id(.:format) credit_card#show
您正在使用 Singular Resources
:
resources :credit_card
你必须使用的地方 Plural Resources
:
resources :credit_cards
使用resources :credit_cards
代替resources :credit_card
我有基于模型的表单:
<h2>Add New Credit Card</h2>
<%= form_for @credit_card do |f| %>
some fields
<% end %>
路线:
resources :credit_card
credit_card_index GET /credit_card(.:format) credit_card#index
POST /credit_card(.:format) credit_card#create
new_credit_card GET /credit_card/new(.:format) credit_card#new
edit_credit_card GET /credit_card/:id/edit(.:format) credit_card#edit
credit_card GET /credit_card/:id(.:format) credit_card#show
PATCH /credit_card/:id(.:format) credit_card#update
PUT /credit_card/:id(.:format) credit_card#update
DELETE /credit_card/:id(.:format) credit_card#destroy
控制器:
def new
@credit_card = CreditCard.new
end
当我尝试按表单呈现时,它说:
undefined method `credit_cards_path' for #<#<Class:0x00000004c37680>:0x00000004c34570>
Did you mean? credit_card_path
credit_card_index_path
credit_card_url
它是基于模型的形式,目前我没有模型。我只想渲染和提交将去创建方法
在您的路线中,resources
定义使用复数形式。
resources :credit_cards
这将生成您的路线
credit_cards GET /credit_cards/:id(.:format) credit_card#show
您正在使用 Singular Resources
:
resources :credit_card
你必须使用的地方 Plural Resources
:
resources :credit_cards
使用resources :credit_cards
代替resources :credit_card