Class: Publinator::Manage::PublishableController

Inherits:
ApplicationController show all
Defined in:
app/controllers/publinator/manage/publishable_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#body_id, #current_controller, #current_domain, #current_layout, #current_site, #current_site_name

Instance Method Details

#createObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/publinator/manage/publishable_controller.rb', line 53

def create
  @publishable = @publishable_class.new(params[@publishable_member_name.to_sym])
  logger.info current_site.to_yaml
  @publishable.publication.site = current_site

  if @publishable.save
    redirect_to "/manage/#{@publishable_collection_name}", :notice => "#{@publishable_type.name} created."
  else
    begin
      render "#{@publishable_collection_name}/new", :notice => "#{@publishable_type.name} could not be created."
    rescue ActionView::MissingTemplate
      render "publinator/manage/publishable/new", :notice => "#{@publishable_type.name} could not be created."
    end
  end
end

#editObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/publinator/manage/publishable_controller.rb', line 43

def edit
  @publishable.asset_items.build

  begin
    render "manage/#{@publishable_collection_name}/edit"
  rescue ActionView::MissingTemplate
    render "publinator/manage/publishable/edit"
  end
end

#indexObject



9
10
11
12
13
14
15
# File 'app/controllers/publinator/manage/publishable_controller.rb', line 9

def index
  begin
    render "manage/#{@publishable_collection_name}/index"
  rescue ActionView::MissingTemplate
    render "publinator/manage/publishable/index"
  end
end

#newObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/publinator/manage/publishable_controller.rb', line 25

def new
  @publishable = @publishable_class.new(
    :publication => Publinator::Publication.new(
      :publish_at       => 1.day.from_now.beginning_of_day + 8.hours,
      :archive_at       => 31.days.from_now.beginning_of_day,
      :site             => current_site,
      :publishable_type => @publishable_type.name
    )
  )
  @publishable.asset_items.build
  @field_names = @publishable.editable_fields.collect{ |an| an.to_sym }
  begin
    render "manage/#{@publishable_collection_name}/new"
  rescue ActionView::MissingTemplate
    render "publinator/manage/publishable/new"
  end
end

#showObject



17
18
19
20
21
22
23
# File 'app/controllers/publinator/manage/publishable_controller.rb', line 17

def show
  begin
    render "manage/#{@publishable_collection_name}/show"
  rescue ActionView::MissingTemplate
    render "publinator/manage/publishable/show"
  end
end

#sortObject



81
82
83
84
85
86
87
88
# File 'app/controllers/publinator/manage/publishable_controller.rb', line 81

def sort
  collection_class = @publishable.collection_name.singularize.downcase
  @publishable.menu_collection.each do |item|
    item.position = params[collection_class].index(item.id.to_s) + 1
    item.save
  end
  render :nothing => true
end

#updateObject



69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/publinator/manage/publishable_controller.rb', line 69

def update
  if @publishable_class.send(:update, @publishable.id, params[@publishable_class_name.downcase.to_sym])
    redirect_to "/manage/#{@publishable_collection_name}", :notice => "#{@publishable_type.name} updated."
  else
    begin
      render "#{@publishable_collection_name}/edit", :notice => "#{@publishable_type.name} could not be updated."
    rescue ActionView::MissingTemplate
      render "publinator/manage/publishable/edit", :notice => "#{@publishable_type.name} could not be updated."
    end
  end
end