All pastes #900932 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-02-12 08:13 UTC
rendered paste body
class AdminController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @personne_pages, @personnes = paginate :personnes, :per_page => 10
  end

  def show
    @personne = Personne.find(params[:id])
  end

  def new
    @personne = Personne.new
  end

  def create
    @personne = Personne.new(params[:personne])
    if @personne.save
      flash[:notice] = 'Personne was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @personne = Personne.find(params[:id])
  end

  def update
    @personne = Personne.find(params[:id])
    if @personne.update_attributes(params[:personne])
      flash[:notice] = 'Personne was successfully updated.'
      redirect_to :action => 'show', :id => @personne
    else
      render :action => 'edit'
    end
  end

  def destroy
    Personne.find(params[:id]).destroy
    redirect_to :action => 'list'
  end

 def init_test1
   p = Personne.create :prenom => "Hakim", :nom => "Epleh", :ddn =>"1970-11-28".to_date
   id_he = p.id
   p = Personne.create :prenom => "Alain", :nom => "Terrieur", :ddn =>"1986-01-05".to_date
   id_a1t = p.id
   p = Personne.create :prenom => "Alex", :nom => "Terrieur", :ddn =>"1986-01-05".to_date
   id_a2t = p.id
   p = Personne.create :prenom => "Inès", :nom => "Perret", :ddn =>"1985-08-15".to_date
   id_ip = p.id
   p = Personne.create :prenom => "Gérard", :nom => "Manvussat", :ddn =>"1987-10-03".to_date
   id_gm = p.id
   p = Personne.create :prenom => "Delphine", :nom => "Ariaume", :ddn =>"1986-07-01".to_date
   id_da = p.id
   p = Personne.create :prenom => "Omar", :nom => "Abou", :ddn =>"1965-03-31".to_date
   id_oa = p.id
   #
   e = Etudiant.create :num_isic => "a1t40123456789", :personne_id => id_a1t
   id_a1t = e.id
   e = Etudiant.create :num_isic => "a2t40123456789", :personne_id => id_a2t
   id_a2t = e.id
   e = Etudiant.create :num_isic => "ip340123456789", :personne_id => id_ip
   id_ip = e.id
   e = Etudiant.create :num_isic => "gm340123456789", :personne_id => id_gm
   id_gm = e.id
   e = Etudiant.create :num_isic => "da340123456789", :personne_id => id_da
   id_da = e.id
   #
   uv = Unite.create :nom=>"BD40", :titre=>"Bases de données", :personne_id=>id_he
   id_bd = uv.id
   uv = Unite.create :nom=>"MT54", :titre=>"Mathématiques", :personne_id=>id_oa
   id_mt = uv.id
   uv = Unite.create :nom=>"GL53", :titre=>"Génie Logiciel", :personne_id=>id_oa
   id_gl = uv.id
   #
   eu = EtudiantsUnite.create :etudiant_id => id_ip, :unite_id =>id_mt
   eu = EtudiantsUnite.create :etudiant_id => id_da, :unite_id =>id_mt
   eu = EtudiantsUnite.create :etudiant_id => id_a1t, :unite_id =>id_bd
   eu = EtudiantsUnite.create :etudiant_id => id_a2t, :unite_id =>id_bd
   eu = EtudiantsUnite.create :etudiant_id => id_gm, :unite_id =>id_bd
   eu = EtudiantsUnite.create :etudiant_id => id_a1t, :unite_id =>id_gl
   eu = EtudiantsUnite.create :etudiant_id => id_ip, :unite_id =>id_gl
   eu = EtudiantsUnite.create :etudiant_id => id_gm, :unite_id =>id_gl
   render :text=>"Création OK"
  end


end