{"action":"created","issue":{"url":"https://api.github.com/repos/jaybernal/planner/issues/2","repository_url":"https://api.github.com/repos/jaybernal/planner","labels_url":"https://api.github.com/repos/jaybernal/planner/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/jaybernal/planner/issues/2/comments","events_url":"https://api.github.com/repos/jaybernal/planner/issues/2/events","html_url":"https://github.com/jaybernal/planner/pull/2","id":230248610,"number":2,"title":"Add debugger","user":{"login":"thejonanshow","id":270746,"avatar_url":"https://avatars0.githubusercontent.com/u/270746?v=3","gravatar_id":"","url":"https://api.github.com/users/thejonanshow","html_url":"https://github.com/thejonanshow","followers_url":"https://api.github.com/users/thejonanshow/followers","following_url":"https://api.github.com/users/thejonanshow/following{/other_user}","gists_url":"https://api.github.com/users/thejonanshow/gists{/gist_id}","starred_url":"https://api.github.com/users/thejonanshow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejonanshow/subscriptions","organizations_url":"https://api.github.com/users/thejonanshow/orgs","repos_url":"https://api.github.com/users/thejonanshow/repos","events_url":"https://api.github.com/users/thejonanshow/events{/privacy}","received_events_url":"https://api.github.com/users/thejonanshow/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-21T21:02:13Z","updated_at":"2017-05-21T22:18:11Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jaybernal/planner/pulls/2","html_url":"https://github.com/jaybernal/planner/pull/2","diff_url":"https://github.com/jaybernal/planner/pull/2.diff","patch_url":"https://github.com/jaybernal/planner/pull/2.patch"},"body":"So the create test looks well written, the problem is that create isn't doing what you expect.\r\n\r\nI added a debugger in the create action on your events controller:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/270746/26287338/34df23e6-3e2e-11e7-8d90-36dc59b70d29.png)\r\n\r\nYou're setting `@event` to `event` and `event` is a new, empty event object. I think what you want to do is set some attributes on your new event and then set `@event`.\r\n\r\n```\r\ndef create\r\n  @event = Event.new(event_params)\r\n  # ...\r\nend\r\n```\r\n\r\nYou're also going to need to deal with [strong parameters from Rails](http://edgeguides.rubyonrails.org/action_controller_overview.html#strong-parameters):\r\n\r\n```\r\nprivate\r\n\r\ndef event_params\r\n  params.permit(:id, :event_name, :event_date, :event_time)\r\nend\r\n```\r\n\r\nWould also suggest that you remove the `event_` prefix from your attribute names. We know it's an event name because it's an attribute on an event. Maybe go with :name, :start_date, :start_time.\r\n\r\nTo change a column name with a Rails migration generate a new migration:\r\n\r\n```\r\nrails g migration change_event_event_name_to_name\r\n```\r\n\r\nand then add this line in the change method:\r\n\r\n```\r\nrename_column :table, :old_column, :new_column\r\n```\r\n\r\nI'm not sure what format your datepicker is giving you for a datetime but it likely looks something like this string: `\"2017-07-08 09:10:00 -0700\"`. That's the datetime from FactoryGirl so if the string your datepicker makes is significantly different you may have to adjust the string format. Most likely `DateTime.parse` will know how to handle it:\r\n\r\n```\r\nirb(main):004:0> DateTime.parse \"2017-07-08 09:10:00 -0700\"\r\n=> Sat, 08 Jul 2017 09:10:00 -0700\r\n```\r\n\r\nIf the string is formatted correctly ActiveRecord will actually save it just fine:\r\n\r\n```\r\nirb(main):010:0> time = Time.now.to_s # note the to_s\r\n=> 2017-05-21 14:15:08 -0700\r\nirb(main):011:0> date = Date.today.to_s\r\n=> Sun, 21 May 2017\r\nirb(main):012:0> Event.create(event_name: \"test\", event_date: date, event_time: time)\r\n   (0.2ms)  BEGIN\r\n  SQL (2.3ms)  INSERT INTO \"events\" (\"event_name\", \"event_date\", \"event_time\", \"created_at\", \"updated_at\") VALUES ($1, $2, $3, $4, $5) RETURNING \"id\"  [[\"event_name\", \"test\"], [\"event_date\", \"2017-05-21\"], [\"event_time\", \"22:15:08.634986\"], [\"created_at\", \"2017-05-21 21:15:38.729810\"], [\"updated_at\", \"2017-05-21 21:15:38.729810\"]]\r\n   (0.4ms)  COMMIT\r\n=> #<Event id: 1, event_name: \"test\", event_date: \"2017-05-21\", event_time: \"2000-01-01 22:15:08\", created_at: \"2017-05-21 21:15:38\", updated_at: \"2017-05-21 21:15:38\">\r\n```\r\n\r\nYou also probably want to use a datetime attribute to save both the time and date as a single attribute on your events. If you tell the migration generator the name of the attribute you want to remove and name your migration with the pattern \"remove_ATTRIBUTE_from_TABLE\" then Rails will generate the change method automatically for you:\r\n\r\n```\r\n$ rails g migration remove_event_time_from_events event_time:time\r\n      invoke  active_record\r\n      create    db/migrate/20170521212612_remove_event_time_from_events.rb\r\n$ cat db/migrate/20170521212612_remove_event_time_from_events.rb\r\nclass RemoveEventTimeFromEvents < ActiveRecord::Migration[5.0]\r\n  def change\r\n    remove_column :events, :event_time, :time\r\n  end\r\nend\r\n```\r\n\r\nSo use that to remove your two event time and date columns and add a new attribute called start:\r\n\r\n```\r\nrails g migration add_start_to_events start:datetime\r\n```\r\n\r\nWhich automatically generates this:\r\n\r\n```\r\nclass AddStartToEvents < ActiveRecord::Migration[5.0]\r\n  def change\r\n    add_column :events, :start, :datetime\r\n  end\r\nend\r\n```\r\n\r\nYou can read more about changing tables and naming migrations for automatic change method generation in the [Rails documentation](http://edgeguides.rubyonrails.org/active_record_migrations.html#changing-tables).\r\n\r\nYou may also want to add `null: false` on the end of that `start` attribute. If you know an event will always have a start it's considered a best practice to make sure you have it set at the database level. You can and should use a model validation on this attribute as well to make sure it's present, but setting null to false here will prevent and object from saving to the database with invalid data.\r\n\r\nOf course if you want to be able to make events with null starts then you should leave this off, just wanted to let you know about the option.\r\n\r\nBest,\r\n\r\nJonan"},"comment":{"url":"https://api.github.com/repos/jaybernal/planner/issues/comments/302967210","html_url":"https://github.com/jaybernal/planner/pull/2#issuecomment-302967210","issue_url":"https://api.github.com/repos/jaybernal/planner/issues/2","id":302967210,"user":{"login":"jaybernal","id":16108595,"avatar_url":"https://avatars3.githubusercontent.com/u/16108595?v=3","gravatar_id":"","url":"https://api.github.com/users/jaybernal","html_url":"https://github.com/jaybernal","followers_url":"https://api.github.com/users/jaybernal/followers","following_url":"https://api.github.com/users/jaybernal/following{/other_user}","gists_url":"https://api.github.com/users/jaybernal/gists{/gist_id}","starred_url":"https://api.github.com/users/jaybernal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaybernal/subscriptions","organizations_url":"https://api.github.com/users/jaybernal/orgs","repos_url":"https://api.github.com/users/jaybernal/repos","events_url":"https://api.github.com/users/jaybernal/events{/privacy}","received_events_url":"https://api.github.com/users/jaybernal/received_events","type":"User","site_admin":false},"created_at":"2017-05-21T22:18:11Z","updated_at":"2017-05-21T22:18:11Z","body":"i had made some of those changes on a feature branch. \r\n- change the event attributes names\r\n- updated the strong params\r\n- \r\n\r\n"}}
{"actor":{"display_login":"jaybernal"}}