boissier_app/app/controllers/admin/home_blocks_controller.rb
Nicolas Bally 6abf7679fd initial
2011-05-14 13:36:30 +02:00

55 lines
1.0 KiB
Ruby

# -*- encoding : utf-8 -*-
class Admin::HomeBlocksController < ApplicationController
before_filter :authenticate_admin!
load_and_authorize_resource
def show
end
def edit
@home_block = HomeBlock.find(params[:id])
params[:resource => "home_block"]
end
def update
@home_block = HomeBlock.find(params[:id])
params[:resource => "home_block"]
params_content = params[:home_block].delete(:cible_attributes)
content_type = params[:home_block][:cible_type]
cible_id = params[:home_block][:cible_id].to_i if params[:home_block][:cible_id].to_i != 0
puts cible_id.to_i
if !cible_id
content = content_type.constantize.new(params_content)
else
content = content_type.constantize.find(cible_id)
content.attributes = params_content
end
@home_block.cible = content
if @home_block.update_attributes(params[:home_block])
flash[:notice] = "Le bloc a bien été modifié."
respond_to do |format|
format.js
end
else
respond_to do |format|
format.js { render :action => :edit}
end
end
end
end