better variable initialization in beer controller

This commit is contained in:
Aaro Koivukangas
2023-08-15 14:01:01 +03:00
parent 787afc1fd6
commit 2c1fbf44c8
+6 -3
View File
@@ -1,5 +1,6 @@
class BeersController < ApplicationController
before_action :set_beer, only: %i[show edit update destroy]
before_action :set_breweries_and_styles_for_template, only: [:new, :edit, :create]
# GET /beers or /beers.json
def index
@@ -13,8 +14,6 @@ class BeersController < ApplicationController
# GET /beers/new
def new
@beer = Beer.new
@breweries = Brewery.all
@styles = ["Weizen", "Lager", "Pale ale", "IPA", "Porter", "Lowalcohol"]
end
# GET /beers/1/edit
@@ -32,7 +31,6 @@ class BeersController < ApplicationController
format.html { redirect_to beers_path, notice: "Beer was successfully created." }
format.json { render :show, status: :created, location: @beer }
else
@breweries = Brewery.all
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @beer.errors, status: :unprocessable_entity }
end
@@ -73,4 +71,9 @@ class BeersController < ApplicationController
def beer_params
params.require(:beer).permit(:name, :style, :brewery_id)
end
def set_breweries_and_styles_for_template
@breweries = Brewery.all
@styles = ["Weizen", "Lager", "Pale ale", "IPA", "Porter", "Lowalcohol"]
end
end