Class: ContentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/contents_controller.rb', line 35

def create
  @content = Content.new(params[:content])
  if @content.save
    # respond_with @content
    redirect_to contents_path, notice: "#{@content.slug} created."
  else
    format.html { render action: "new" }
    format.json { render json: @content.errors, status: :unprocessable_entity }
  end
end

#customize_view_pathsObject



92
93
94
95
# File 'app/controllers/contents_controller.rb', line 92

def customize_view_paths 
  c = Content.find_by_ancestry(params[:ancestors].try(:split, '/'), params[:id]) if params[:id]
  prepend_view_path "app/views/contents/#{c.slug}" if c
end

#defineObject



25
26
27
# File 'app/controllers/contents_controller.rb', line 25

def define 
  @content = Content.find(params[:id])
end

#destroyObject



81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/contents_controller.rb', line 81

def destroy
  @content = Content.find_by_ancestry(params[:ancestors].try(:split,'/'), params[:id])
  @content.destroy

  respond_to do |format|
    format.html { redirect_to contents_url}
    format.json { head :no_content }
  end

end

#editObject



18
19
20
21
22
23
# File 'app/controllers/contents_controller.rb', line 18

def edit
  @content = Content.find_by_ancestry(params[:ancestors].try(:split,'/'), params[:id]) 
  # @content.build_seo unless @content.seo
  # @content.child_contents.create(slug:"#{@content.slug}-kid-#{@content.child_contents.count}", title:"#{@content.slug} Kid") if @content.child_contents.size == 0
  respond_with @content
end

#indexObject

helper_method :link_to_add_fields



9
10
11
12
# File 'app/controllers/contents_controller.rb', line 9

def index
  @contents = Content.all
  respond_with @contents
end

#modifyObject

TODO add code here to build-up embedded objects in the edited object via ajax



60
61
62
63
# File 'app/controllers/contents_controller.rb', line 60

def modify
  @content = Content.find(params[:id])

end

#newObject



14
15
16
# File 'app/controllers/contents_controller.rb', line 14

def new
  @content = Content.new
end

#renovateObject

PUT /foos/1 PUT /foos/1.json



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

def renovate
  @content = Content.find(params[:id])
  @content.renovate(params[:content][:defn])
  if @content.save
    redirect_to contents_path, notice: "#{@content.slug} definition updated."
  else
    respond_to do |format|
      format.html { render action: "define" }
      format.json { render json: @content.errors, status: :unprocessable_entity }
    end
  end
end

#showObject

Content.all_entries



29
30
31
32
# File 'app/controllers/contents_controller.rb', line 29

def show    # Content.all_entries
  @content = Content.find_by_ancestry(params[:ancestors].try(:split,'/'), params[:id])
  respond_with @content
end

#updateObject



46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/contents_controller.rb', line 46

def update
  @content = Content.find_by_ancestry(params[:ancestors].try(:split,'/'), params[:id])
  if @content.update_attributes(params[:content])
    redirect_to contents_path, notice: "#{@content.title} updated."
  else
    respond_to do |format|
      format.html { render action: "edit" }
      format.json { render json: @content.errors, status: :unprocessable_entity }
    end
  end
end