Class: Spree::Admin::PostsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/admin/posts_controller.rb', line 15

def create
  @post = Spree::Post.new(post_params)
  if @post.save
    flash[:notice] = "Post saved successfully"
    redirect_to admin_posts_path
  else
    flash[:alert] = "There was an error saving your post"
    redirect_to :back
  end
end

#destroyObject



41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/spree/admin/posts_controller.rb', line 41

def destroy
  @post = Spree::Post.find(params[:id])
  if @post.destroy
    flash[:notice] = "Post removed successfully"
    redirect_to admin_posts_path
  else
    flash[:alert] = "There was an error removing the post"
    redirect_to :back
  end
end

#editObject



26
27
28
# File 'app/controllers/spree/admin/posts_controller.rb', line 26

def edit
  @post = Spree::Post.find(params[:id])
end

#indexObject



3
4
5
# File 'app/controllers/spree/admin/posts_controller.rb', line 3

def index
  @posts = Spree::Post.all
end

#newObject



11
12
13
# File 'app/controllers/spree/admin/posts_controller.rb', line 11

def new
  @post = Spree::Post.new
end

#showObject



7
8
9
# File 'app/controllers/spree/admin/posts_controller.rb', line 7

def show
  @post = Spree::Post.find(params[:id])
end

#updateObject



30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/spree/admin/posts_controller.rb', line 30

def update
  @post = Spree::Post.find(params[:id])
  if @post.update_attributes(post_params)
    flash[:notice] = "Post saved successfully"
    redirect_to admin_posts_path
  else
    flash[:alert] = "There was an error saving your post"
    redirect_to :back
  end
end