Class: K3cms::Blog::BlogPostsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/k3cms/blog/blog_posts_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#current_ability

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/k3cms/blog/blog_posts_controller.rb', line 31

def create
  @blog_post.attributes = params[:k3cms_blog_blog_post]
  @blog_post.author = current_user

  respond_to do |format|
    if @blog_post.save
      format.html do
        #redirect_to(k3cms_blog_blog_post_url(@blog_post),

        redirect_to(k3cms_blog_blog_posts_url(:focus => "##{dom_id(@blog_post)} .editable[data-attribute=title]"),
                    :notice => 'Blog post was successfully created.')
      end
      format.xml  { render :xml => @blog_post, :status => :created, :location => @blog_post }
      format.json { render :nothing =>  true }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @blog_post.errors, :status => :unprocessable_entity }
      format.json { render :nothing =>  true }
    end
  end
end

#destroyObject



70
71
72
73
74
75
76
77
78
# File 'app/controllers/k3cms/blog/blog_posts_controller.rb', line 70

def destroy
  @blog_post.destroy
  respond_to do |format|
    #format.html { redirect_to(k3cms_blog_blog_posts_url) }
    format.html { redirect_to k3cms_blog_blog_posts_url }
    format.xml  { head :ok }
    format.json { render :nothing =>  true }
  end
end

#editObject



53
54
# File 'app/controllers/k3cms/blog/blog_posts_controller.rb', line 53

def edit
end

#indexObject



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

def index
  @blog_posts = @blog_posts.order('id desc')
  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml  => @blog_posts }
    format.json { render :json => @blog_posts }
  end
end

#newObject



23
24
25
26
27
28
29
# File 'app/controllers/k3cms/blog/blog_posts_controller.rb', line 23

def new
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml  => @blog_post }
    format.json { render :json => @blog_post }
  end
end

#showObject



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

def show
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml  => @blog_post }
    format.json { render :json => @blog_post }
  end
end

#updateObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/k3cms/blog/blog_posts_controller.rb', line 56

def update
  respond_to do |format|
    if @blog_post.update_attributes(params[:k3cms_blog_blog_post])
      format.html { redirect_to(k3cms_blog_blog_post_url(@blog_post), :notice => 'Blog post was successfully updated.') }
      format.xml  { head :ok }
      format.json { render :json => {} }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @blog_post.errors, :status => :unprocessable_entity }
      format.json { render :json => {:error => @blog_post.errors.full_messages.join('<br/>')} }
    end
  end
end