Skip to content

Instantly share code, notes, and snippets.

@coderforhire
Created January 30, 2012 18:31
Show Gist options
  • Save coderforhire/1705842 to your computer and use it in GitHub Desktop.
Save coderforhire/1705842 to your computer and use it in GitHub Desktop.
class Event < ActiveRecord::Base
has_event_calendar
belongs_to :user
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :events
end
class CreateEvents < ActiveRecord::Migration
def self.up
create_table :events do |t|
t.string :name
t.datetime :start_at
t.datetime :end_at
t.timestamps
end
end
def self.down
drop_table :events
end
end
class AddUserIdToEvents < ActiveRecord::Migration
def change
add_column :events, :user_id, :integer
end
end
@coderforhire
Copy link
Author

cat app/views/events/new.html.erb

New event

<%= render 'form' %>

<%= link_to 'Back', events_path %>
afresta@afresta:~/rails_projects/YC_dev$ cat app/views/events/_form.html.erb
<%= form_for(@event) do |f| %>
<% if @event.errors.any? %>


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

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

<% end %>

<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :start_at %>
<%= f.text_field :start_at %>
  <div><%= f.label :user_id %><br />
  <%= f.text_field :user_id %></div>
<%= f.submit %>
<% end %>

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