Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8841573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:45:08+00:00 2026-06-14T10:45:08+00:00

… used in orderscontroller#new to create an array, which is used in a select

  • 0

… used in orderscontroller#new to create an array, which is used in a select method of a form field in views, which is supposed to add a new order

Hullo there,

So my error is this

Routing Error

undefined local variable or method `array_of_payment_types’ for #

Now, I’ve got this select field for a form to submit a new order, but my browser won’t load the page with the form:

<div class="field">
    <%= f.label :pay_type %><br />
    <%= f.select :payment_type_id, Order::PAYMENTS_TYPES,
                 :prompt => 'Select a payment method' %>
</div>

This is using an array that I am trying to create twice:

class Order < ActiveRecord::Base

...
  belongs_to :payment_type

  **PAYMENT_TYPES = array_of_payment_types**

  validates :name, :address, :email
  validates :pay_type, :inclusion => { :in => PAYMENT_TYPES }

...

  **def array_of_payment_types
    PaymentType.pluck(:pay_type_name)
  end**
end

and here:

class OrdersController < ApplicationController

...

  def new
    @cart = current_cart
    if @cart.line_items.empty?
      redirect_to store_url, :notice => "Your cart is empty"
      return
    end

    **@PAYMENT_TYPES = array_of_payment_types**
    @hide_checkout_button = true
    @order = Order.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @order }
    end
  end

...

end

while the method to create the array, which “plucks” the entries from the :pay_type_name column Payment_Type table, is declared both in order.rb and the ApplicationController, here:

class ApplicationController < ActionController::Base
  protect_from_forgery

  private

...

    def array_of_payment_types
      PaymentType.pluck(:pay_type_name)
    end 
end

Now I am trying to use the same process as other pieces of my application, just replicating stuff I have already done. For example, in OrdersController#new I’ve got

@cart = current_cart

current_cart is a method declared in the ApplicationsController and it works. So why doesn’t array_of_payment_types also work?

Thanks for your help in advance 🙂

Further information…

What I am trying to do with this is to create a new order, using a form, and one of the fields in the form enters a “pay_type” (or payment type in English). I want to present the user with options which is a list “plucked” from the entries in the PaymentType table, column :pay_type_name (I may be repeating myself, but no harm). But the new Order is created after the Order#new action, which is where I have created the array. Where/how should I create the array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:45:09+00:00Added an answer on June 14, 2026 at 10:45 am

    def array_of_payment_types in your Order class defines an instance method and you are trying to use it as a class method.

    I’d just define array_of_payment_types as a class method instead and call Order.array_of_payment_types instead of the constant ARRAY_OF_PAYMENT_TYPES in your view.

    You can always cache it in the class method, there’s no need to use a constant for this.

    def self.array_of_payment_types
       @array_of_payment_types ||= PaymentType.pluck(:pay_type_name)
    end
    

    But, consider leaving the responsibility for the payment type array in the PaymentType class. The Order class shouldn’t be the point of contact to retrieve data which is clearly under the control of another class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form, one of the fields is a select field, with 5
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
Why does the Android system throw this Exception? 05-18 12:33:44.169 W/System.err( 8230): java.io.IOException: Is
I would like to run a str_replace or preg_replace which looks for certain words
I want to sign a message according to the RSA-SHA1 Signature Method in OAuth
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
what about this one: I want to format the currentTime displayed by a videoPlayer
English is not my native language. I need a software to spellcheck and correct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.