Skip to content

Instantly share code, notes, and snippets.

@ionas
Created September 12, 2010 01:58
Show Gist options
  • Save ionas/575763 to your computer and use it in GitHub Desktop.
Save ionas/575763 to your computer and use it in GitHub Desktop.
class CreateContentelements < ActiveRecord::Migration
def self.up
create_table :contentelements do |t|
t.string :name
t.text :data
t.references :elementdefinition
t.timestamps
end
end
def self.down
drop_table :contentelements
end
end
class CreateElementdefinitions < ActiveRecord::Migration
def self.up
create_table :elementdefinitions do |t|
t.string :name
t.text :description
t.text :options
t.text :template
t.timestamps
end
end
def self.down
drop_table :elementdefinitions
end
end
class Contentelement < ActiveRecord::Base
belongs_to :elementdefinition
end
class Elementdefinition < ActiveRecord::Base
has_many :contentlements
end
@ionas
Copy link
Author

ionas commented Sep 12, 2010

New contentelement

<%= render 'form' %>

<%= link_to 'Back', contentelements_path %>

form

<%= form_for(@contentelement) do |f| %>
<% if @contentelement.errors.any? %>


<%= pluralize(@contentelement.errors.count, "error") %> prohibited this contentelement from being saved:

  <ul>
  <% @contentelement.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
</div>

<% end %>

<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :data %>
<%= f.text_area :data %>
<%= f.label :elementdefinition %>
<%= f.text_field :elementdefinition %>
<%= f.submit %>
<% end %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment