Я пробовал много способов, чтобы связать эти модели хорошим и чистым способом, но, как обычно, для любого новичка я делаю что-то глупое, чего не вижу.Пожалуйста, может кто-нибудь мне поможет?
модель пользователя
class User < ActiveRecord::Base
has_one :house, :dependent => :destroy
accepts_nested_attributes_for :house, :allow_destroy => true
end
модель дома
class House < ActiveRecord::Base
belongs_to :user
belongs-to :type
end
модель типа
class Type < ActiveRecord::Base
has_many :houses
accepts_nested_attributes_for :houses
end
контроллер типа
class TypesController < ApplicationController
def new
@type = Type.new
end
def create
@type = Type.new(params[:type])
@type.houses = current_user.house
if @type.save
redirect_to edit_house_path
flash[:success] = "yeah"
else
render :new
end
end
end
тип new_view
<div>
<%= form_for @type, :url => types_path, :method => :post do |t| %>
<%= t.fields_for :house do |h| %>
<%= h.label :name %><%= h.text_field :name %>
<% end %>
<ul>
<li>test_1:<%= t.radio_button :kind, "test_1" %></li>
<li>test_2:<%= t.radio_button :kind, "test_2" %></li>
<li>test_3:<%= t.radio_button :kind, "test_3" %></li>
</ul>
<%= t.submit "create", :class => "blue" %>
<% end %>
</div>