|
| 1 | +class JournalsController < ApplicationController |
| 2 | + load_and_authorize_resource |
| 3 | + check_authorization |
| 4 | + |
| 5 | + before_action :set_journal, only: %i[ show edit update destroy ] |
| 6 | + |
| 7 | + # GET /journals or /journals.json |
| 8 | + def index |
| 9 | + @journals = Journal.all.order(created_at: :desc).limit(100) |
| 10 | + end |
| 11 | + |
| 12 | + # GET /journals/1 or /journals/1.json |
| 13 | + def show |
| 14 | + end |
| 15 | + |
| 16 | + # GET /journals/new |
| 17 | + def new |
| 18 | + @journal = Journal.new |
| 19 | + end |
| 20 | + |
| 21 | + # GET /journals/1/edit |
| 22 | + def edit |
| 23 | + end |
| 24 | + |
| 25 | + # POST /journals or /journals.json |
| 26 | + def create |
| 27 | + @journal = Journal.new(journal_params) |
| 28 | + |
| 29 | + respond_to do |format| |
| 30 | + if @journal.save |
| 31 | + format.html { redirect_to journal_url(@journal), notice: "Journal was successfully created." } |
| 32 | + format.json { render :show, status: :created, location: @journal } |
| 33 | + else |
| 34 | + format.html { render :new, status: :unprocessable_entity } |
| 35 | + format.json { render json: @journal.errors, status: :unprocessable_entity } |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + # PATCH/PUT /journals/1 or /journals/1.json |
| 41 | + def update |
| 42 | + respond_to do |format| |
| 43 | + if @journal.update(journal_params) |
| 44 | + format.html { redirect_to journal_url(@journal), notice: "Journal was successfully updated." } |
| 45 | + format.json { render :show, status: :ok, location: @journal } |
| 46 | + else |
| 47 | + format.html { render :edit, status: :unprocessable_entity } |
| 48 | + format.json { render json: @journal.errors, status: :unprocessable_entity } |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + # DELETE /journals/1 or /journals/1.json |
| 54 | + def destroy |
| 55 | + @journal.destroy |
| 56 | + |
| 57 | + respond_to do |format| |
| 58 | + format.html { redirect_to journals_url, notice: "Journal was successfully destroyed." } |
| 59 | + format.json { head :no_content } |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + private |
| 64 | + # Use callbacks to share common setup or constraints between actions. |
| 65 | + def set_journal |
| 66 | + @journal = Journal.find(params[:id]) |
| 67 | + end |
| 68 | + |
| 69 | + # Only allow a list of trusted parameters through. |
| 70 | + def journal_params |
| 71 | + params.require(:journal).permit(:req, :notes, :params, :token) |
| 72 | + end |
| 73 | +end |
0 commit comments