Skip to content

Instantly share code, notes, and snippets.

@JeanMertz
Created August 3, 2010 09:46
Show Gist options
  • Save JeanMertz/506120 to your computer and use it in GitHub Desktop.
Save JeanMertz/506120 to your computer and use it in GitHub Desktop.
# MODELS:
class Stencil < ActiveRecord::Base
has_one :stencil_config, :dependent => :destroy
accepts_nested_attributes_for :stencil_config
end
class StencilConfig < ActiveRecord::Base
belongs_to :stencil
end
# CONTROLLERS:
class Admin::StencilsController < ApplicationController
# GET /admin/stencils/new
def new
@stencil = Stencil.new
@stencil.build_stencil_config
end
end
class Admin::StencilConfigsController < ApplicationController
# GET /admin/stencil_configs/new
def new
@stencil_config = StencilConfig.new
end
end
#VIEW _FORM (trimmed):
<%= form_for([:admin, @stencil]) do |f| %>
<div class="field">
<%= f.label :client %><br />
<%= f.select(:client_id, Client.find(:all).collect {|c| [ c.name, c.id ] }) %>
</div>
<% f.fields_for :stencil_config do |stencil_config| %>
asd asd
<div class="field">
<%= stencil_config.label :title %><br />
<%= stencil_config.text_field :title %>
</div>
<div class="field">
<%= stencil_config.label :description %><br />
<%= stencil_config.text_area :description %>
</div>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment