ruby on rails - NoMethod Error - One to Many Association -


trying debug hours not making sense

the error is:

undefined method `proposals' nil:nilclass 

i have 2 one-to-many associations in following models:

entrepreneur.rb ...  has_many :findentrepreneurs, :dependent => :destroy ... 

finentrepreneur.rb

 belongs_to :entrepreneur     has_many :proposals 

proposal.rb

belongs_to :findentrepreneur 

i did nested routing model using following:

resources :entrepreneurs              resources :messages                collection                  post :delete_selected                end              end              resources :findentrepreneurs             resources :proposals           end            end 

and proposals_controller.rb new action

def new     @proposal = @findentrepreneurs.proposals.new      respond_to |format|       format.html # new.html.erb       format.json { render json: @proposal }     end   end 

hope can help

thankyou

nowhere initialize @findentrepreneurs. rails isn't magic, need assign variable before use it. otherwise, value nil, , error you're seeing, telling you've invoked method proposals on nil.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -