Skip to content

Instantly share code, notes, and snippets.

@jeantil
Created October 21, 2010 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeantil/639142 to your computer and use it in GitHub Desktop.
Save jeantil/639142 to your computer and use it in GitHub Desktop.
class EventsController < ApplicationController
rescue_from(ActionController::RoutingError) {redirect_to '/'}
def index
render :layout=>"layouts/home"
end
def show
if params[:name]
@event=Event.where(:name=>params[:name]).first
@event||=Event.create(:name=>params[:name])
end
@event||=Event.where(:id=>params[:id]).first
respond_to do |format|
if @event
format.html
else
format.html {redirect_to new_event_path}
end
end
end
def create
@event=Event.new(params[:event])
if(@event.save)
@participant=@event.participants.new()
redirect_to @event
else
render :new
end
end
def new
@event=Event.new
end
def search
@email=params[:search].downcase
@events=Event.select("DISTINCT events.*").joins(:participants).where(:participants=>{:email=>@email}).to_a if @email
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment