Has_one Value and Creating a New Entry in Rails 3

I have the following models, Member and Map, configured like this:

class Member < ActiveRecord::Base ... has_one :map, :dependent => :destroy ... class Map < ActiveRecord::Base belongs_to :member 

and my routes are configured with:

 resources :members do resources :maps end 

and my card controller:

  def new @map = Map.new end def create @map = current_member.map.new(params[:map]) if @map.save..... 

But when I try to save a new map, I get an undefined method 'new' error message on this line. I'm not sure why.

+6
source share
1 answer

Here is a description of all the methods added by the has_one association. You must use build_map to build a new map.

+10
source

Source: https://habr.com/ru/post/897582/


All Articles