Changeset 1221

Show
Ignore:
Timestamp:
07/22/08 20:27:21 (6 months ago)
Author:
alban
Message:

Selectionne le Show en fonction du host de la request. Fixes #3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/public_controller.rb

    r1211 r1221  
    77 
    88  def welcome 
    9     @episodes_last =  Episode.find(:all, :order => "created_at DESC", :limit => 10) 
     9    if @show.blank? 
     10      if request.host =~ /((www.)bonnes-ondes.fr|localhost)/ 
     11        @episodes_last =  Episode.find(:all, :order => "created_at DESC", :limit => 10) 
     12      else 
     13        raise ActiveRecord::RecordNotFound 
     14      end 
     15    else 
     16      render_show 
     17    end 
    1018  end 
    1119 
    1220  def show 
    13     create_visit @show 
    14     render :layout => "public_render" 
     21    render_show 
    1522  end 
    1623 
     
    3643  private 
    3744 
    38   def assigns_show 
    39     @show = find_show unless params[:show_slug].blank? 
     45  def render_show 
     46    create_visit @show 
     47    render :layout => "public_render", :action => :show 
    4048  end 
    4149 
    42   def find_show 
    43     return @show unless @show.blank? 
     50  def assigns_show 
     51    host = Host.find_by_name(request.host) 
     52    unless host.blank? 
     53      @show = host.show 
     54    end 
    4455 
    45     show = Show.find_by_slug(params[:show_slug]) 
    46     raise ActiveRecord::RecordNotFound if show.nil? 
    47     show 
     56    show_slug = "" 
     57    if request.host =~ /^(.*).bonnes-ondes.fr$/ 
     58      show_slug = $1 
     59    end 
     60 
     61    @show = find_show(show_slug) 
     62  end 
     63 
     64  def find_show(slug = nil) 
     65    @show ||= Show.find_by_slug(slug) 
    4866  end 
    4967