LearningROR LearningROR - 1 year ago 41
Ruby Question

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 %>


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

When I try to render by form it says:

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

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

Answer Source

You're using the Singular Resources:

resources :credit_card

Where you have to use Plural Resources:

resources :credit_cards