Skip to content

Instantly share code, notes, and snippets.

@joshnabbott
Created September 9, 2010 16:30
Show Gist options
  • Save joshnabbott/572114 to your computer and use it in GitHub Desktop.
Save joshnabbott/572114 to your computer and use it in GitHub Desktop.
class Parent
belongs_to :child, :autosave => true, :polymorphic => true
end
class SomethingController
def create
@parent = Parent.new(params[:parent])
@parent.child = child
if @parent.save
# blah
else
# eff
end
end
private
def child
type = params[:parent][:child_type]
type.new(params[type.underscore])
end
end
<%= form_for @parent do |f| %>
<%= f.text_field :child_type >
<% end =%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment