Class: Newsly::TemplatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/newsly/templates_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
# File 'app/controllers/newsly/templates_controller.rb', line 5

def index
	@templates = Newsly::Template.where(:draft => false).order('friendly_name')
   @template_types = Newsly::Template.all.map(&:template_type).uniq
end

#publishObject



38
39
40
41
42
# File 'app/controllers/newsly/templates_controller.rb', line 38

def publish
  @draft = Newsly::Template.find(params[:id])
  @draft.publish
  render :text => "Published"
end

#send_testObject



29
30
31
32
33
34
35
# File 'app/controllers/newsly/templates_controller.rb', line 29

def send_test
  @template = Newsly::Template.find(params[:id])
  if Newsly::Mailer.build_mail(@template.id, params[:to], Newsly.test_data).deliver
    render :text => "Okidoki"
  end

end

#showObject



10
11
12
13
14
15
16
17
18
# File 'app/controllers/newsly/templates_controller.rb', line 10

def show
   @template = Newsly::Template.where(:parent_id => params[:id], :draft => true).first
   if @template.nil?
     @template = Newsly::Template.find(params[:id]).dup
     @template.draft = true
     @template.parent_id = params[:id]
     @template.save
   end
end

#updateObject



20
21
22
23
24
25
26
27
# File 'app/controllers/newsly/templates_controller.rb', line 20

def update
  @template = Newsly::Template.find(params[:id])
  if @template.update_attributes(params[:template])
    render :text => "Last saved #{distance_of_time_in_words_to_now(Time.now, true)} ago"
  else
    render :text => "Kunde inte sparas"
  end
end