Class: Workarea::Storefront::BlogEntriesController

Inherits:
Storefront::ApplicationController
  • Object
show all
Defined in:
app/controllers/workarea/storefront/blog_entries_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_commentObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/workarea/storefront/blog_entries_controller.rb', line 14

def add_comment
  model = Content::BlogEntry.find_by(slug: params[:blog_entry_id])
  @entry = Storefront::BlogEntryViewModel.new(model, view_model_options)

  if current_user.public_info.blank?
    if params[:first_name].blank? || params[:last_name].blank?
      flash[:error] = 'First and last name are required'
      render(:show) && return
    else
      current_user.update_attributes(params.permit(:first_name, :last_name))
    end
  end

  @comment = model.comments.build(comment_params)

  if @comment.save
    flash[:success] = 'Your comment has been submitted. Thanks!'
    redirect_to blog_entry_path(@entry)
  else
    flash[:error] = 'There was a problem saving your comment.'
    render :show
  end
end

#showObject

Raises:

  • (InvalidDisplay)


7
8
9
10
11
12
# File 'app/controllers/workarea/storefront/blog_entries_controller.rb', line 7

def show
  model = Content::BlogEntry.find_by(slug: params[:id])
  raise InvalidDisplay unless model.active?

  @entry = Storefront::BlogEntryViewModel.new(model, view_model_options)
end