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

  • Home
  • SEARCH
  • 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 8008251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:04:43+00:00 2026-06-04T18:04:43+00:00

I have a problem with the money currency gem. I’m trying to show a

  • 0

I have a problem with the money currency gem. I’m trying to show a dropdown with all currencies:

The View:

<% if @receipt.errors.any? %>
<div id="error_explanation">
  <h2><%= pluralize(@receipt.errors.count, "error") %> prohibited this receipt from being saved:</h2>
  <ul>
    <% @receipt.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
    <% end %>
  </ul>
</div>
<% end %>
<%= simple_form_for(@receipt, :html => {:class => 'form-horizontal', :multipart => true }) do |f| %>
<h3>Kassenzettel hinzufügen</h3>
  <p>
  <div class="input-prepend">
    <%= f.label :due_date, 'Ausstellungsdatum' -%>
    <span class="add-on"><i class="icon-calendar"></i></span><%= f.text_field :due_date,  :value => Date.today.strftime('%d.%m.%Y'), :class => 'datepicker span2', :"data-date-format" => :'dd.mm.yyyy' %>
    </p>
    <p>
    <%= f.label :due_time, 'Zeit (optional)' -%>

    <%= f.time_select :due_time, { :class => "adsf"} %>
    </p>
    <p>
      <%= f.select(:currency,all_currencies(Money::Currency::TABLE), {:include_blank => 'Select a Currency'}) %>

    </p>
    <p> <%= f.label :recipt, 'Datei hochladen' -%> <%= f.file_field :document -%>
    <p class="help-block">Akzeptierte Formate: PDF, JPG, TIFF, max. 1 MB</p>
    </p>
    <br />
    <p>
      <button type="submit" class="btn btn-success"><i class="icon-plus icon-white"></i> Dokument hinzufügen </button>
      <%= link_to 'Abbrechen', receipts_path, :class => "btn" %></p>  
<% end %>

The Model:

class Receipt < ActiveRecord::Base  

    belongs_to :user
    has_many   :products, :dependent => :destroy
    self.per_page = 5   
    validates :due_date, :presence => true
    validates_attachment :document, :presence => true,            
              :size => { :in => 0..5024.kilobytes }
    has_attached_file :document,
    :styles => {
        :minithumb=> ["50x50#", :png],
        :thumb=> ["150x150#", :png],
        :small  => ["500>", :png]       },
    :convert_options => { :all => '-background white -flatten +matte'}
    attr_accessible :due_date, :due_time, :receiptissuedate, :document, :dependent => :destroy
    columns_hash["due_time"] = ActiveRecord::ConnectionAdapters::Column.new("due_time", nil, "time")

    composed_of :receiptfinalamount,
        :class_name => "Money",
        :mapping => [%w(receiptfinalamount cents), %w(receiptcurrency currency_as_string)],
        :constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) },
        :converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }

    before_validation(:on => :create) do
        self.receiptissuedate = DateTime.new(self.due_date.year, self.due_date.month, self.due_date.day, self.due_time.hour, self.due_time.min)
    end

    before_save :default_values
    def default_values
        self.receiptfinalamount ||= 0
    end

    def due_date
        return @due_date if @due_date.present?
        return Date.today
    end

    def due_time
        return @due_time if @due_time.present?
        return Time.now
    end 


    def due_date=(new_date)
        @due_date = self.string_to_datetime(new_date, I18n.t('date.formats.default'))
    end


    def due_time=(new_time)
        @due_time = self.string_to_datetime(new_time, I18n.t('time.formats.time'))
    end

    protected

    def string_to_datetime(value, format)
        return value unless value.is_a?(String)

        begin
            DateTime.strptime(value, format)
        rescue ArgumentError
            nil
        end
    end

end

The Controller:

class ReceiptsController < ApplicationController


  helper_method :sort_column, :sort_direction

  # GET /receipts
  # GET /receipts.json
  def index
    #@receipts = Receipt.all
    @receipts = current_user.receipts.order(sort_column + " " + sort_direction).paginate(:page => params[:page]).order('receiptissuedate DESC') 

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @receipts }     
    end
  end


  # GET /receipts/1
  # GET /receipts/1.json
  def show
    @receipt = current_user.receipts.find(params[:id])
    @products = current_user.receipts.find(params[:id]).products.all
    @product = Product.new

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @receipt }
    end
  end

  # GET /receipts/new
  # GET /receipts/new.json
  def new

    @receipt = Receipt.new

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

  # GET /receipts/1/edit
  def edit
    @receipt = Receipt.find(params[:id])
  end

  # POST /receipts
  # POST /receipts.json
  def create
    @receipt = current_user.receipts.new(params[:receipt])

    respond_to do |format|
      if @receipt.save
        format.html { redirect_to receipts_url, notice: 'Receipt was successfully created.' }
        format.json { render json: @receipt, status: :created, location: @receipt }
      else
        format.html { render action: "new" }
        format.json { render json: @receipt.errors, status: :unprocessable_entity }
      end
    end
  end
  # PUT /receipts/1
  # PUT /receipts/1.json
  def update
    @receipt = current_user.receipts.find(params[:id])

    respond_to do |format|
      if @receipt.update_attributes(params[:receipt])
        format.html { redirect_to @receipt, notice: 'Receipt was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @receipt.errors, status: :unprocessable_entity }
      end
    end
  end


  # DELETE /receipts/1
  # DELETE /receipts/1.json
  def destroy
    @receipt = current_user.receipts.find(params[:id])
    @receipt.destroy

    respond_to do |format|
      format.html { redirect_to receipts_url }
      format.json { head :no_content }
    end
  end

  private

  def sort_column
    Receipt.column_names.include?(params[:sort]) ? params[:sort] : "receiptissuedate"
  end

  def sort_direction
    %w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
  end
end

The error:

NameError in Receipts#new

Showing /Users/dastrika/Documents/RailsProjects/receipter/app/views/receipts/_form_new.html.erb where line #22 raised:

uninitialized constant Money::Currency::TABLE

Extracted source (around line #22):

19: <%= f.label :due_time, ‘Zeit (optional)’ -%>
20:
21: <%= f.time_select :due_time, { :class => “adsf”} %>
22:

23:

24: <%= f.select(:currency,all_currencies(Money::Currency::TABLE), {:include_blank => ‘Select a Currency’}) %>
25:

Trace of template inclusion: app/views/receipts/new.html.erb

Rails.root: /Users/dastrika/Documents/RailsProjects/receipter
Application Trace | Framework Trace | Full Trace

app/views/receipts/_form_new.html.erb:22:in block in _app_views_receipts__form_new_html_erb__159753442_6920660'
app/views/receipts/_form_new.html.erb:11:in
_app_views_receipts__form_new_html_erb__159753442_6920660′
app/views/receipts/new.html.erb:7:in _app_views_receipts_new_html_erb__164008852_34408570'
app/controllers/receipts_controller.rb:38:in
new’

  • 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-04T18:04:45+00:00Added an answer on June 4, 2026 at 6:04 pm

    This syntax is incorrect

    Money::Currency::TABLE
    

    You want

    all_currencies(Money::Currency.table)
    
    def all_currencies(hash)
      hash.keys
    end
    

    http://rubymoney.github.com/money/

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

Sidebar

Related Questions

I have problem with show or hide form in Window Form Application. I start
I have model Product with fields price_cents and price_currency. Money default currency is USD.
Ok so i have this problem i am trying to address. I have this
I have a little problem with export data to csv (comma-separated values). All data
I have a little problem with export data to csv (comma-separated values). All data
We're using Ruby's Money gem. In our application, we're also converting between currencies. So
I have problem with JDBC application that uses MONEY data type. When I insert
I trying to build my own multi dropdown menu, and i encounter this problem
I have an app included into INSTALLED_APPS that needs to be monkey-patched. The problem
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar

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.