Class: PagesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/pages_controller.rb

Overview

@File Name : pages_controller.rb

@Company Name              : Mindfire Solutions Private Limited
@Creator Name              : Vikram Kumar Mishra
@Date Created              : 2012-06-05
@Date Modified             :
@Last Modification Details :
@Purpose                   : To setup the communication between page model and views related to pages for users,
                             It's yet to be implemented.

Instance Method Summary collapse

Instance Method Details

#homeObject

GET / or GET /home return : none



26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/pages_controller.rb', line 26

def home

  # send data in different format
  respond_to do |format|

    format.html{ render :template => 'mcms_pages/pages/show'}# home.html.erb
    format.json { render json: @page }

  end # end respond_to block

end

#previewObject

GET /pages/1 or GET /pages/page-title GET /pages/1.json or GET /pages/page-title.json return : none



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/controllers/pages_controller.rb', line 76

def preview

  if get_page(page_not_found = false)

    # Preview existing pages
    @page.attributes = params[:page]

  elsif params[:page]

    # Preview a non-persisted page
    @page = Page.new(params[:page])

    # initializing a loop variable
    i = @page.page_parts.length

    # looping through page_parts_pages to retrieve all page_parts
    params[:page]["page_parts_pages_attributes"].each do |k,v|

      # retrieve existing page_parts from DB and assign it to @page array
      @page.page_parts[i] = PagePart.find_by_id(v["page_part_id"]);

      i = i + 1 # incrementing the loop variable

    end # end loop

  end # end if

  # send data in different format
  respond_to do |format|

    format.html{ render :template => 'mcms_pages/pages/show'}
    format.json { render json: @page }

  end # end respond_to block

end

#showObject

GET /1 or GET /page-title GET /1.json or GET /page-title.json return : none



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/pages_controller.rb', line 43

def show

  # if page is not publeshed
  if not @page.published?

    # show page 404
    page_404_error

  # if link_url is present for page
  elsif @page.link_url.present? and @page.link_url != '/404'

    # redirect to given link url
    redirect_to @page.link_url

  else

    # send data in different format
    respond_to do |format|

      format.html{ render :template => 'mcms_pages/pages/show'}# show.html.erb
      format.json { render json: @page }

    end # end respond_to block

  end # end if

end