Class: Phcpresspro::Article::PostsController

Inherits:
Phcpresspro::ApplicationController show all
Defined in:
app/controllers/phcpresspro/article/posts_controller.rb

Instance Method Summary collapse

Methods inherited from Phcpresspro::ApplicationController

#user_for_paper_trail

Instance Method Details

#createObject

POST



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

def create
  @article_post = Article::Post.new(article_post_params)
  @article_post.user_id = current_user.id
  @article_post.org_id = current_user.org_id
  if @article_post.save
    @article_post.connections.build
    redirect_to article_posts_url, notice: 'Post was successfully created.'
    else
      render :new
  end
end

#destroyObject

DELETE



59
60
61
62
# File 'app/controllers/phcpresspro/article/posts_controller.rb', line 59

def destroy
@article_post.destroy
  redirect_to article_posts_url, notice: 'Post was successfully destroyed.'
end

#editObject

Article Edit



30
31
# File 'app/controllers/phcpresspro/article/posts_controller.rb', line 30

def edit
end

#indexObject

Article Index



12
13
14
# File 'app/controllers/phcpresspro/article/posts_controller.rb', line 12

def index
  @article_posts = Article::Post.where(org_id: current_user.org_id)
end

#newObject

Article New



23
24
25
26
27
# File 'app/controllers/phcpresspro/article/posts_controller.rb', line 23

def new
  @article_post = Article::Post.new
  @article_post.user_id = current_user.id
  @article_post.org_id = current_user.org_id
end

#showObject

Article Show



17
18
19
20
# File 'app/controllers/phcpresspro/article/posts_controller.rb', line 17

def show
  @article_post = Article::Post.friendly.find(params[:id])
  @versions = PaperTrail::Version.where(item_id: params[:id], item_type: 'Phcpresspro::Article::Post')
end

#updateObject

PATCH/PUT



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

def update
  @article_post.user_id = current_user.id
  @article_post.org_id = current_user.org_id
  if @article_post.update(article_post_params)
    @article_post.connections.build
    redirect_to article_posts_url, notice: 'Post was successfully updated.'
    else
      render :edit
  end
end