Forked from noltedesign/gist:42995606b94a0b4780a8
Last active
October 16, 2015 21:22
-
-
Save johnmaxwell/0a08144b0e968c94bd31 to your computer and use it in GitHub Desktop.
This file contains 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 EventsController < ApplicationController | |
before_filter :authenticate_user! | |
def index | |
end | |
def show | |
@event = Event.find_by_id(params[:id]) | |
end | |
def new | |
@event = Event.new | |
end | |
def create | |
@event = Event.new(event_params) | |
if @event.start | |
flash[:success] = "Event Created" | |
redirect_to @event | |
else | |
render 'new' | |
end | |
end | |
private | |
def event_params | |
params[:event][:owner_id] = current_user.id | |
params.require(:event).permit(:owner_id, :name, :description, :image, :street_address, :city, :state_province, :zip, :repeat_event, :repeat_interval, :repeat_holidays, :event_end) | |
end | |
end | |
class Event < ActionRecord::Base | |
has_many :event_instances | |
def start | |
save.tap do |did_save| | |
create_first_instance if did_save | |
end | |
end | |
private | |
def create_first_instance | |
event_instances.create! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment