Undefined method & ldquo; _path & rdquo; in the rails

advertisements

I am trying to create a new model and provide user a link to a form to fill the model object.

My model (/models/paypal_order):

class PaypalOrder < ActiveRecord::Base
    attr_accessor :card_number, :card_verification

end

My controller (controllers/paypal_order_controller.rb):

class PaypalOrderController < ApplicationController

    def new
        @paypal_order = PaypalOrder.new
    end

end

My view (views/paypal_order/new.html.erb):

<%form_for PaypalOrder.new do |f|%>  #also tried <%form_for @paypal_order do |f|%>
<%= f.error_messages %>
<p>
    <%= f.label :first_name %><br />
    <%= f.text_field :first_name %>
</p>
<p>
    <%= f.label :last_name %><br />
    <%= f.text_field :last_name %>
</p>
<p>
    <%= f.label :card_type %><br />
    <%= f.select :card_type, [["Visa","visa"],["MasterCard", "master"],["Discover","discover"],["American Express","american_express"]] %>
</p>
<p>
    <%= f.label :card_number %><br />
    <%= f.text_field :card_number %>
</p>
<p>
    <%= f.label :card_verification, "Card Verification Value (CVV)" %><br />
    <%= f.text_field :card_verification %>
</p>
<p>
    <%= f.label :card_expires_on %><br />
    <%= f.text_field :card_expires_on, :discard_day =>true, :start_year => Date.today.year, :end_year => (Date.today.year+25), :add_month_numbers => true %>
</p>
<%end%>

The link:

  <div class="payment_options">
  <div class="available_payment_options">
  <div class="online_payment_option">
    <h3>PayPal</h3>
    <%= link_to "Checkout", new_paypal_order_path %>
  </div>

entry in routes.rb:

resources :paypal_order

But on clicking the link I'm getting the following error:

NoMethodError in Paypal_order#new

Showing /home/nish/repos/new/test/voylla_staging_changes/app/views/paypal_order/new.html.erb where line #1 raised:

undefined method `paypal_orders_path' for #<#<Class:0x101f7e98>:0x101e5b94>
Extracted source (around line #1):

1: <%form_for PaypalOrder.new do |f|%>
2:  <%= f.error_messages %>
3:  <p>
4:      <%= f.label :first_name %><br />

I am not able to understand why I am getting this error. Also why is the form looking for paypal_order**s**_path, shouldn't it be paypal_order_path instead

EDIT rake routes output:

                               paypal_order_index GET    /paypal_order(.:format)                                                   {:action=>"index", :controller=>"paypal_order"}
                                                  POST   /paypal_order(.:format)                                                   {:action=>"create", :controller=>"paypal_order"}
                                 new_paypal_order GET    /paypal_order/new(.:format)                                               {:action=>"new", :controller=>"paypal_order"}
                                edit_paypal_order GET    /paypal_order/:id/edit(.:format)                                          {:action=>"edit", :controller=>"paypal_order"}
                                     paypal_order GET    /paypal_order/:id(.:format)                                               {:action=>"show", :controller=>"paypal_order"}
                                                  PUT    /paypal_order/:id(.:format)                                               {:action=>"update", :controller=>"paypal_order"}
                                                  DELETE /paypal_order/:id(.:format)                                               {:action=>"destroy", :controller=>"paypal_order"}


First change first line to:

<%= form_for @paypal_order do |f|%>

second change routes to :

resources :paypal_orders

Also change controller class to

class PaypalOrdersController < ApplicationController

..
end

And controller file name to paypal_orders_controller.rb