Class: Blog::Gem::AuthorsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_author, #login_as_author

Instance Method Details

#createObject



47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/blog/gem/authors_controller.rb', line 47

def create
  @author = Blog::Gem::Author.new(author_params)
  respond_to do |format|
    if @author.save
      format.html { redirect_to "#{Blog::Gem.path}/authors/me/edit", notice: 'Author was successfully created.' }
    else
      format.html { render :new }
    end
  end
end

#destroyObject



68
69
70
71
72
73
74
# File 'app/controllers/blog/gem/authors_controller.rb', line 68

def destroy
  @author.destroy
  respond_to do |format|
    format.html { redirect_to authors_url, notice: 'Author was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject



44
45
# File 'app/controllers/blog/gem/authors_controller.rb', line 44

def edit
end

#indexObject



34
35
36
37
# File 'app/controllers/blog/gem/authors_controller.rb', line 34

def index
  @authors = Blog::Gem::Author.all
  @page_title = "Listing Authors"
end

#loginObject



21
22
23
24
25
26
# File 'app/controllers/blog/gem/authors_controller.rb', line 21

def 
  if session[:author_id].present?
    redirect_to blogs_path
  end
  @page_title = "Author Login"
end

#login_submitObject



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/blog/gem/authors_controller.rb', line 10

def 
  @page_title = "Author Login"
  if Blog::Gem::Author.find_by(public_email: params[:email]).try(:authenticate, params[:password])
    session[:author_id] = Blog::Gem::Author.find_by(public_email: params[:email]).id
    redirect_to blogs_path, notice: "You are Logged in!"
  else
    flash[:error] = "The password or email is incorrect."
    render :login
  end
end

#logoutObject



28
29
30
31
# File 'app/controllers/blog/gem/authors_controller.rb', line 28

def logout
  session[:author_id] = nil
  redirect_to blogs_path
end

#newObject



39
40
41
42
# File 'app/controllers/blog/gem/authors_controller.rb', line 39

def new
  @author = Blog::Gem::Author.new
  @page_title = "New Authors"
end

#updateObject



58
59
60
61
62
63
64
65
66
# File 'app/controllers/blog/gem/authors_controller.rb', line 58

def update
  respond_to do |format|
    if @author.update(author_params)
      format.html { redirect_to "#{Blog::Gem.path}/authors/me/edit", notice: 'Author was successfully updated.' }
    else
      format.html { render :edit }
    end
  end
end