2016-07-27 8 views
0

Ich habe modellbasierte Form:Unable Modell basierte Formulare erstellen Schienen 4

<h2>Add New Credit Card</h2> 
<%= form_for @credit_card do |f| %> 
    some fields 
<% end %> 

Routen:

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 

Controller:

def new 
    @credit_card = CreditCard.new 
end 

Wenn ich von Form zu machen, versuchen Sie es sagt:

undefined method `credit_cards_path' for #<#<Class:0x00000004c37680>:0x00000004c34570> 
Did you mean? credit_card_path 
       credit_card_index_path 
       credit_card_url 

Es ist eine modellbasierte Form, für jetzt habe ich nichts im Modell. Ich möchte nur rendern und übermitteln wird gehen zu erstellen Methode

Antwort

3

generieren Sie verwenden die Singular Resources:

resources :credit_card 

Wo Sie haben Plural Resources zu verwenden:

resources :credit_cards 
+0

was ist das: 'resources: credit_history'? – LearningROR

+0

Alles hängt davon ab, was Sie brauchen. Ich habe auch die Links zur Dokumentation gepostet, also sieh es dir an. – Vucko

3

In Ihren Routen verwenden Sie Plural für resources Definition.

resources :credit_cards 

Das Ihre Routen wie

credit_cards GET /credit_cards/:id(.:format)     credit_card#show 
1

Verwenden resources :credit_cards statt resources :credit_card