Class: Blog::ContextsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/blog/contexts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#can_manage_blogs, #can_manage_contexts

Methods included from BlogsHelper

#allowable_html, #construct_blog_path, #posted_by_on

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/blog/contexts_controller.rb', line 34

def create
  @context = Context.new(params[:context])
  
  respond_to do |format|
    if @context.save
      notice = "The '#{@context.context_type}' context was successfully created."
      format.html { redirect_to @context, :notice => notice }
      format.json { render :json => @context, :status => :created, :location => @context }
    else
      format.html { render :action => "new" }
      format.json { render :json => @context.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/blog/contexts_controller.rb', line 65

def destroy
  context = Blog::Context.find_by_id(params[:id])
  notice = "The '#{context.context_type}' context has been destroyed. Please remove the entries from you routes file"

  context.destroy
  
  respond_to do |format|
    format.html { redirect_to contexts_path, :notice => notice }
    format.json { head :ok }
  end
end

#editObject



29
30
31
# File 'app/controllers/blog/contexts_controller.rb', line 29

def edit
  @context = Context.find(params[:id])
end

#indexObject



6
7
8
9
10
11
12
13
# File 'app/controllers/blog/contexts_controller.rb', line 6

def index
  @contexts = Context.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render :json => @contexts }
  end
end

#newObject



24
25
26
# File 'app/controllers/blog/contexts_controller.rb', line 24

def new
  @context = Context.new
end

#showObject



15
16
17
18
19
20
21
22
# File 'app/controllers/blog/contexts_controller.rb', line 15

def show
  @context = Context.find(params[:id])
  
  respond_to do |format|
    format.html # show.html.erb
    format.json { render :json => @context }
  end
end

#updateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/blog/contexts_controller.rb', line 50

def update
  @context = Context.find(params[:id])
  
  respond_to do |format|
    if @context.update_attributes(params[:context])
      notice = "The '#{@context.context_type}' context was successfully updated."
      format.html { redirect_to context_path(@context), :notice => notice }
      format.json { head :ok }
    else
      format.html { render :action => "edit" }
      format.json { render :json => @context.errors, :status => :unprocessable_entity }
    end
  end
end