Skip to content

Instantly share code, notes, and snippets.

@dmuneras
Created December 15, 2010 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dmuneras/742091 to your computer and use it in GitHub Desktop.
Save dmuneras/742091 to your computer and use it in GitHub Desktop.
class WorkshopsController < BaseController
include Viewable
load_and_authorize_resource :except => :index
# before_filter :load_header, :only => [:directorio, :laboratorios]
uses_tiny_mce(:only => [:edit, :update, :create, :new]) do
AppConfig.default_mce_options
end
def index
redirect_to Page.find(102) and return
@workshops = Workshop.comming_soon.paginate :page => params[:page]
@rss_title = "#{AppConfig.community_name}: Próximos Talleres y Laboratorios"
respond_to do |format|
format.html{ raise CanCan::AccessDenied and return if @user.nil? }
format.rss {
render_rss_feed_for(@workshops,
{ :feed => {:title => @rss_title, :link => "http://docentes.eafit.edu.co/talleres" },
:item => {:title => :title_with_category,
:description => :summary,
:link => Proc.new {|workshop| workshop_url(workshop)},
:pub_date => :created_at} })
}
end
end
def show
@workshop = Workshop.find(params[:id])
raise ActiveRecord::RecordNotFound unless @workshop
end
def new
@workshop = Workshop.new
end
def create
@workshop = Workshop.new(params[:workshop])
@workshop.tag_list = params[:tag_list] || ''
if params[:published]
logger.info "********************pase^^^^^^^^^^^^^^^^"
@workshop.update_attributes(:published => true)
else
@workshop.update_attributes(:published => false)
end
if @workshop.save
begin
Event.new_from_workshop(@workshop, current_user.id, workshop_url(@workshop))
flash[:notice] = "El taller ha sido creado con éxito, además se creó un evento relacionado"
rescue Exception => e
flash[:notice] = "El taller ha sido creado con éxito"
flash[:error] = "No se ha podido crear un evento para este taller (#{e.message})"
end
redirect_to @workshop
else
render :action => 'new'
end
end
def edit
@workshop = Workshop.find(params[:id])
end
def update
@workshop = Workshop.find(params[:id])
@workshop.tag_list = params[:tag_list] || ''
if params[:published]
logger.info "********************pase^^^^^^^^^^^^^^^^"
@workshop.update_attributes(:published => true)
else
@workshop.update_attributes(:published => false)
end
if @workshop.update_attributes(params[:workshop])
flash[:notice] = "El taller se ha editado con éxito"
redirect_to @workshop
else
render :action => 'edit'
end
end
def destroy
@workshop = Workshop.find(params[:id])
@workshop.destroy
flash[:notice] = "El taller ha sido eliminado"
redirect_to workshops_url
end
def directorio
@header = SectionHeader.find(4)
@workshops = Workshop.comming_soon.workshops_published.paginate :page => params[:page]
@title = "Talleres prácticos"
end
def laboratorios
@header = SectionHeader.find(6)
@workshops = Workshop.comming_soon.labs_published.paginate :page => params[:page]
@title = "Experimenta con laboratorios tecnológicos"
render :action => 'directorio'
end
def galeria_talleres
@workshops = Workshop.all
render :action => 'directorio'
end
private
def load_header
begin
@header = SectionHeader.find(4) || SectionHeader.first || SectionHeader.new
rescue Exception => e
true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment