mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
better variable initialization in beer controller
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user