Created
July 31, 2012 17:34
-
-
Save tjarmain/3218787 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
############ Models ############ | |
class Fund < ActiveRecord::Base | |
attr_accessible :name | |
has_many :portfolios | |
end | |
class Investment < ActiveRecord::Base | |
attr_accessible :portfolio_id, :stock_id | |
belongs_to :portfolio | |
belongs_to :stock | |
end | |
class Portfolio < ActiveRecord::Base | |
attr_accessible :fund_id, :period | |
belongs_to :fund | |
has_many :investments | |
has_many :stocks, :through => :investments | |
end | |
class Stock < ActiveRecord::Base | |
attr_accessible :issuer | |
has_many :investments | |
has_many :portfolios, :through => :investments | |
end | |
############ controllers/funds_controller.rb ############ | |
def show | |
@fund = Fund.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render :json => @fund } | |
end | |
end | |
############ views/funds/show.html.erb ############ | |
<%= form_for(@fund) do |f| %> | |
<%= f.collection_select :period, @fund.portfolios(:all), :id, :period %> | |
<%= f.submit %> | |
<% end %> | |
############ Error I receive ############ | |
NoMethodError in Funds#show | |
Showing /Users/tory/dev/gator/app/views/funds/show.html.erb where line #17 raised: | |
undefined method `period' for #<Fund:0x103d9d128> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment