Class: SitesController

Inherits:
InheritedResources::Base
  • Object
show all
Defined in:
lib/generators/squeezer/templates/app/controllers/sites_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /sites POST /sites.xml



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/squeezer/templates/app/controllers/sites_controller.rb', line 32

def create    
  @site = Site.new(params[:site])
  respond_to do |format|
    if @site.save
      flash[:notice] = 'El sitio fue creado'
      format.html { redirect_to(:controller=>"users",:action=>'sign_up') }
      format.xml  { render :xml => @site, :status => :created, :location => @site }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @site.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



65
66
67
68
69
# File 'lib/generators/squeezer/templates/app/controllers/sites_controller.rb', line 65

def destroy
  @site = Site.last
  @site.destroy
  redirect_to(@site)
end

#editObject

GET /sites/1/edit



21
22
23
24
25
26
27
28
# File 'lib/generators/squeezer/templates/app/controllers/sites_controller.rb', line 21

def edit
  if site
    @site = site
    @files = Dir.open("public/stylesheets/ice")
  else
    redirect_to({:action=>new})
  end
end

#newObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/generators/squeezer/templates/app/controllers/sites_controller.rb', line 4

def new
  @files = Dir.open("public/stylesheets/ice")
  @site=site
  if(!@site)
    @site = Site.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @site }
    end
  else
    flash[:notice]="el sitio ya fue creado"
    
  end
end

#updateObject

PUT /sites/1 PUT /sites/1.xml



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/squeezer/templates/app/controllers/sites_controller.rb', line 48

def update
  @site = Site.find(params[:id])
     
  respond_to do |format|
    if @site.update_attributes(params[:site])
      files = Dir.open("public/stylesheets/ice/#{@site.style}/ice")
      FileUtils.cp_r files ,"app/views/layouts/ice/#{@site.style}"
      flash[:notice] = 'Site was successfully updated.'
      format.html { redirect_to(@site) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @site.errors, :status => :unprocessable_entity }
    end
  end
end