-
Notifications
You must be signed in to change notification settings - Fork 1
Feature create event #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9362931
597596c
c3a242e
cc56c09
747561b
47d00ae
d9d040e
49c91e1
5e3e5f6
2fc53d8
9986bf5
c40b0b8
0e54fc4
7217d11
98e7458
bb61d98
fbee4cf
58212df
96b4c8a
6159650
5834b22
7764419
41df701
59dee52
7ebb5de
303d96e
802b3d3
dace2d7
15be8a6
27bfcf6
6cd53bc
cccdedd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,53 @@ | ||
| class EventsController < ApplicationController | ||
| before_action :find_event, only: [ :edit, :show ] | ||
| before_action :find_event, only: [ :edit, :show, :update ] | ||
| before_action :event_params, only: [ :update ] | ||
|
|
||
| def index | ||
| @events = Event.all | ||
| end | ||
|
|
||
| def new | ||
| end | ||
|
|
||
| def edit | ||
| @event = Event.new | ||
| end | ||
|
|
||
| def show | ||
| end | ||
|
|
||
| def create | ||
| @event = current_user.events.new event_params | ||
| if current_user.save | ||
| flash[:notice] = 'Successfully created' | ||
| redirect_to events_path | ||
| else | ||
| flash[:error] = 'Something went wrong' | ||
| render new_event_path | ||
| end | ||
| end | ||
|
|
||
| def update | ||
| def edit | ||
| @event = Event.find(params[:id]) | ||
| if @event.update_attributes(@params) | ||
| flash[:notice] = "Event updated successfully" | ||
| end | ||
|
|
||
| def update | ||
| if @event.update event_params | ||
| flash[:notice] = "Event updated successfully" | ||
| redirect_to events_path | ||
| else | ||
| flash[:notice] = "Event wasn't updated as expected" | ||
| redirect_to :back | ||
| flash[:notice] = "Event wasn't updated as expected" | ||
| render :edit | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def event_params | ||
| @params = params.require(:event).permit(:name, :details, :location) | ||
| @params = params.require(:event).permit! | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this one, but does this allow mass-assignment of time-stamp fields? (i.e.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Private: The attribute cannot be changed via mass-assignment, I think we are good here but not really sure, let's discuss about it...what do you think @joiggama ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory it does allow mass-assignment of anything within 🍭
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOL 3 years later
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOL
Ruben Betancourt |
||
| end | ||
|
|
||
| def find_event | ||
| @event = Event.find(params[:id]) | ||
| end | ||
|
|
||
|
|
||
| @event = Event.find(params[:id]) | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,23 @@ | ||
| # == Schema Information | ||
| # | ||
| # Table name: events | ||
| # | ||
| # id :integer not null, primary key | ||
| # name :string(255) | ||
| # details :text | ||
| # user_id :integer | ||
| # latitude :string(255) | ||
| # longitude :string(255) | ||
| # location_name :string(255) | ||
| # scheduled_at :datetime | ||
| # created_at :datetime | ||
| # updated_at :datetime | ||
| # | ||
|
|
||
| class Event < ActiveRecord::Base | ||
| validates_presence_of :name, :details, :user_id | ||
| belongs_to :user | ||
| validates_presence_of :name, :user_id | ||
|
|
||
| # Note: Make sure that this doesn't conflict with ActiveRecord | ||
| attr_accessor :where | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| class User < ActiveRecord::Base | ||
| has_many :events | ||
|
|
||
| def self.create_with_omniauth auth | ||
| create! do |user| | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| = render partial: 'layouts/error_messages', locals: { resource: @event} | ||
|
|
||
| = form_for @event do |f| | ||
| = f.label :name | ||
| = f.text_field :name | ||
| = f.label :details | ||
| = f.text_area :details | ||
| = f.label :location | ||
| = f.text_field :location_name | ||
| = f.submit | ||
| %p | ||
| = f.label :event_name | ||
| = f.text_field :event_name | ||
| %p | ||
| = f.label :information | ||
| = f.text_area :information_details | ||
| %p | ||
| = f.label :location_name | ||
| = f.text_field :location_name | ||
| %p | ||
| = f.label :where | ||
| = f.text_field :where | ||
| %p | ||
| = f.label :when | ||
| = f.text_field :scheduled_at | ||
| %p | ||
| = f.submit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| %h1 Hackd.mx | ||
| %p This is a dummy home page | ||
| %p This is a dummy home page |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fabrication.configure do |config| | ||
| config.fabricator_path = 'spec/fabricators' | ||
| config.path_prefix = Rails.root | ||
| config.sequence_start = 10000 | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At line 37 you use
render action: 'edit'and here you use a path helper. Isn't this somewhat inconsistent?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch