1class Admin::NotesController < Admin::AdminController
 
2  before_action :fetch_petition
 
3  before_action :fetch_note
 
4
 
5  rescue_from ActiveRecord::RecordNotUnique do
 
6    @note = @petition.note(true) and update
 
7  end
 
8
 
 9  def show
 
10    render 'admin/petitions/show'
 
11  end
 
 
13  def update
 
14    if @note.update(note_params)
 
15      redirect_to [:admin, @petition]
 
16    else
 
17      render 'admin/petitions/show'
 
18    end
 
19  end
 
 
21  private
 
 
23  def fetch_note
 
24    @note = @petition.note || @petition.build_note
 
25  end
 
 
27  def fetch_petition
 
28    @petition = Petition.find(params[:petition_id])
 
29  end
 
 
31  def note_params
 
32    params.require(:note).permit(:details)
 
33  end
 
34end