Class: Backend::RedirectsController

Inherits:
BaseController
  • Object
show all
Includes:
Concerns::PaginationController
Defined in:
app/controllers/backend/redirects_controller.rb

Instance Method Summary collapse

Methods included from Concerns::PaginationController

#page_number, #paginate, #per_page

Methods inherited from BaseController

#breadcrumb, #current_admin, #default_app_locale, #translate_notice

Methods included from Udongo::Cryptography

#crypt

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/backend/redirects_controller.rb', line 17

def create
  @redirect = Redirect.new(allowed_params).decorate

  if @redirect.save
    @redirect.jumps_cacher.cache!
    redirect_to backend_redirects_path, notice: translate_notice(:added, :redirect)
  else
    render :new
  end
end

#destroyObject



28
29
30
31
32
# File 'app/controllers/backend/redirects_controller.rb', line 28

def destroy
  @redirect.destroy
  @redirect.jumps_cacher.cache! unless @redirect.jumps_cacher.already_on_top?
  redirect_to backend_redirects_path(search_params), notice: translate_notice(:deleted, :redirect)
end

#editObject



38
39
40
# File 'app/controllers/backend/redirects_controller.rb', line 38

def edit
  session['redirect_search_params'] = search_params
end

#indexObject



7
8
9
10
11
# File 'app/controllers/backend/redirects_controller.rb', line 7

def index
  @search = Redirect.ransack params[:q]
  results = @search.result(distinct: true).order('times_used DESC')
  @redirects = paginate(results).decorate
end

#newObject



13
14
15
# File 'app/controllers/backend/redirects_controller.rb', line 13

def new
  @redirect = Redirect.new(status_code: 301).decorate
end

#search_paramsObject



51
52
53
54
55
56
# File 'app/controllers/backend/redirects_controller.rb', line 51

def search_params
  hash = { q: nil }
  hash[:q] = params[:q].to_hash if params[:q]
  hash[:page] = params[:page] if params[:page]
  hash
end

#showObject



34
35
36
# File 'app/controllers/backend/redirects_controller.rb', line 34

def show
  render layout: false
end

#updateObject



42
43
44
45
46
47
48
49
# File 'app/controllers/backend/redirects_controller.rb', line 42

def update
  if @redirect.update_attributes allowed_params
    @redirect.jumps_cacher.cache!
    redirect_to backend_redirects_path(session[:redirect_search_params]), notice: translate_notice(:edited, :redirect)
  else
    render :edit
  end
end