Class: Admin::NewslettersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/newsletters_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



48
49
50
51
52
53
54
55
56
# File 'app/controllers/admin/newsletters_controller.rb', line 48

def create
  if @newsletter.save
    flash[:notice] = I18n.t('newsletter.create.success').capitalize
    redirect_to([forgeos_cms, :edit, :admin, @newsletter])
  else
    flash[:error] = I18n.t('newsletter.create.failed').capitalize
    render :new
  end
end

#destroyObject



58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/admin/newsletters_controller.rb', line 58

def destroy
   @deleted = @newsletter.destroy
  if @deleted
    flash[:notice] = I18n.t('newsletter.destroy.success').capitalize
    return redirect_to([forgeos_cms, :admin, :newsletters]) if !request.xhr?
  else
    flash[:error] = I18n.t('newsletter.destroy.failed').capitalize
  end
  render :nothing => true
end

#editObject



30
31
32
# File 'app/controllers/admin/newsletters_controller.rb', line 30

def edit

end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/admin/newsletters_controller.rb', line 5

def index
  respond_to do |format|
    format.html
    format.json do
      sort
      render :layout => false
    end
    format.csv do
      params[:iDisplayLength] = 1000000
      sort
      csv_string = FasterCSV.generate( {:force_quotes => true}) do |csv|
        csv << @newsletters.first.attributes.keys

        @newsletters.each do |record|
          csv << record.attributes.values
        end

      end
      send_data csv_string,
      :type => 'text/csv; charset=utf-8; header=present',
      :disposition => "attachment; filename=#{controller_name}.csv"
    end
  end
end

#newObject



44
45
46
# File 'app/controllers/admin/newsletters_controller.rb', line 44

def new

end

#updateObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/admin/newsletters_controller.rb', line 34

def update
  if @newsletter.update_attributes(params[:newsletter])
    flash[:notice] = I18n.t('newsletter.update.success').capitalize
    redirect_to([forgeos_cms, :edit, :admin, @newsletter])
  else
    flash[:error] = I18n.t('newsletter.update.failed').capitalize
    render :action => 'edit'
  end
end