class Admin::BannersController

Controller de administracion para los banners de la pagina de inicio

Public Instance Methods

create() click to toggle source
# File app/controllers/admin/banners_controller.rb, line 41
def create
  @banner=Banner.new(params[:banner])
  if @banner.save
    flash[:notice] = "El nuevo banner se ha guardado correctamente"
    redirect_to admin_banners_path
  else
    render :action => :new
  end
end
destroy() click to toggle source

Eliminar un banner

# File app/controllers/admin/banners_controller.rb, line 67
def destroy
  banner=Banner.find(params[:id])
  if banner.destroy
    respond_to do |format|
      format.html {
        flash[:notice]='El banner se ha eliminado'
        redirect_to admin_banners_path
      }
      format.js {
        render :update do |page| 
          page.visual_effect :fade, "banner_#{banner.id}"
        end
      }
    end
  else
    respond_to do |format|
      format.html {
        flash[:error]='El banner NO se ha eliminado correctamente'
      }
      format.js {
        render :update do |page|
          page.alert "El banner NO se ha eliminado correctamente"
        end  
      }
    end
  end
end
edit() click to toggle source

Actualizar los datos de un banner ya existente

# File app/controllers/admin/banners_controller.rb, line 52
def edit
  @banner=Banner.find(params[:id])
end
index() click to toggle source

Listado de todos los banners con la imagen y el alt del idioma y el enlace

# File app/controllers/admin/banners_controller.rb, line 27
def index
  # @banners=Banner.paginate :page => params[:page], :per_page => 10, :order => "position DESC"
  @banners=Banner.all(:order => "active DESC, position DESC")
end
new() click to toggle source

Crear un nuevo banner

# File app/controllers/admin/banners_controller.rb, line 37
def new
  @banner=Banner.new
end
show() click to toggle source

No se si sera necesario mostrar un banner en administracion

# File app/controllers/admin/banners_controller.rb, line 33
def show
end
sort() click to toggle source

Sera necesario poder ordenarlos ¿quizas drag &drop?

# File app/controllers/admin/banners_controller.rb, line 96
def sort
  @banners=Banner.find(:all)
  @banners.each do |banner|
    new_position = params["banners-list"].reverse.index(banner.id.to_s)+1
    banner.update_attributes(:position => new_position)
  end 

  render :nothing => true
end
update() click to toggle source
# File app/controllers/admin/banners_controller.rb, line 56
def update
  @banner=Banner.find(params[:id])
  if @banner.update_attributes(params[:banner])
    flash[:notice] = "El banner se ha guardado correctamente"
    redirect_to admin_banners_path
  else
    render :action => :edit
  end    
end