Created
January 30, 2012 18:31
-
-
Save coderforhire/1705842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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.text_field :name %>
<%= f.label :start_at %>
<%= f.text_field :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
Processing by EventsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Hn4+rVALJhmXbsZIiQwKNA7YRRkXKwbJwbmrxGAqBPc=", "event"=>{"name"=>"TEST EVENT", "start_at"=>"2012-01-30", "user_id"=>""}, "commit"=>"Create Event"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
(0.3ms) BEGIN
SQL (1.4ms) INSERT INTO "events" ("created_at", "end_at", "name", "start_at", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" ["created_at", Mon, 30 Jan 2012 19:11:41 UTC +00:00], ["end_at", nil], ["name", "TEST EVENT"], ["start_at", Mon, 30 Jan 2012 00:00:00 UTC +00:00], ["updated_at", Mon, 30 Jan 2012 19:11:41 UTC +00:00], ["user_id", nil] COMMIT
Redirected to http://0.0.0.0:3000/events/17
Completed 302 Found in 23ms (ActiveRecord: 12.1ms)