Class: BrickLayer::RoutesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/brick_layer/routes_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#authenticate, #current_administrator

Instance Method Details

#createObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/brick_layer/routes_controller.rb', line 49

def create
  if params[:parent].blank?
    @route = BrickLayer::Route.new(params[:brick_layer_route])
  else
    @route = BrickLayer::Route.children_of(params[:parent]).build(params[:brick_layer_route])
  end
  
  if @route.save
    flash[:success] = "Route Saved!"
    redirect_to edit_route_path(@route)
  else
    render "new"
  end
end

#destroyObject



73
74
75
76
77
# File 'app/controllers/brick_layer/routes_controller.rb', line 73

def destroy
  @route.destroy
  flash[:success] = "Route Removed!"
  redirect_to routes_path
end

#editObject



22
23
24
25
26
27
28
29
# File 'app/controllers/brick_layer/routes_controller.rb', line 22

def edit
  @routes = BrickLayer::Route.all.reject { |x| x.full_path_cache.include?(@route.slug) }
  @routes = @routes.collect do |x| 
    display = x.full_path_cache.blank? ? "/" : x.full_path_cache
    display = "--- Change Parent ---" if x.id == @route.parent_id
    [display, x.id]
  end
end

#indexObject



7
8
9
10
11
12
# File 'app/controllers/brick_layer/routes_controller.rb', line 7

def index
  respond_to do |format|
    format.html
    format.json { render :json => BrickLayer::Route.all }
  end
end

#newObject



14
15
16
17
18
19
20
# File 'app/controllers/brick_layer/routes_controller.rb', line 14

def new
  if params[:parent].blank?
    @route = BrickLayer::Route.new
  else
    @route = BrickLayer::Route.children_of(params[:parent]).build
  end
end

#showObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/brick_layer/routes_controller.rb', line 31

def show
  if params[:path].blank?
    @route = BrickLayer::Route.root      
  else
    @route = BrickLayer::Route.where(:full_path_cache => "/#{params[:path]}").first
  end

  @model_constant = "PageDataSets::#{@route.data_set_template}".constantize unless @route.data_set_template.blank?
  
  if @route.data_set.blank?
    @data_set = nil
  else
    @data_set = @model_constant.new(@route.data_set.attributes)
  end
  
  respond_with(@data_set)
end

#updateObject



64
65
66
67
68
69
70
71
# File 'app/controllers/brick_layer/routes_controller.rb', line 64

def update
  if @route.update_attributes(params[:brick_layer_route]) && valid_data_set?(@route)
    flash[:success] = "Route Updated!"
    redirect_to edit_route_path(@route)
  else
    render "new"
  end
end