Search code examples
ruby-on-railsform-helpers

Unable to create model based forms rails 4


I have model based form:

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

routes:

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

When I try to render by form it says:

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

Its a model based form, for now I have nothing in model. I just want to render and submit will go to create method


Solution

  • You're using the Singular Resources:

    resources :credit_card
    

    Where you have to use Plural Resources:

    resources :credit_cards