Created
October 31, 2012 19:52
-
-
Save lxcodes/3989396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"Calendar", | |
"unit_price":15.00, | |
"expense_account_id":"5072d350d57debd2b900001d", | |
"income_account_id":"5072d350d57debd2b900000a", | |
"description":"This is a test calendar item that will be sold on the online store" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Item | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
field :name, type: String | |
field :active, type: Boolean, default: true | |
field :desc, type: String | |
field :unit_price, type: Money | |
has_one :expense_account, class_name: "Account" | |
has_one :income_account, class_name: "Account" | |
validates :expense_account, presence: true | |
validates :income_account, presence: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ItemsController < ApplicationController | |
skip_before_filter :verify_authenticity_token | |
before_filter :authorize | |
respond_to :json, :xml | |
def create | |
@item = @current_user.items.build(params[:item]) | |
@item.unit_price = Money.parse(params[:item][:unit_price]) | |
@item.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to fix this -- I needed to reverse the relations between items and accounts