mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
added basic routes + controllers + views
This commit is contained in:
@@ -1,2 +1,60 @@
|
|||||||
class StylesController < ApplicationController
|
class StylesController < ApplicationController
|
||||||
|
def show
|
||||||
|
@style = Style.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
@styles = Style.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@style = Style.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@style = Style.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@style = Style.new(style_params)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @style.save
|
||||||
|
format.html { redirect_to style_url(@style), notice: "Style was successfully created." }
|
||||||
|
format.json { render :show, status: :created, location: @style }
|
||||||
|
else
|
||||||
|
format.html { render :new, status: :unprocessable_entity }
|
||||||
|
format.json { render json: @style.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@style = Style.find params[:id]
|
||||||
|
respond_to do |format|
|
||||||
|
if @style.update(style_params)
|
||||||
|
format.html { redirect_to style_url(@style), notice: "Style was successfully updated." }
|
||||||
|
format.json { render :show, status: :ok, location: @style }
|
||||||
|
else
|
||||||
|
format.html { render :edit, status: :unprocessable_entity }
|
||||||
|
format.json { render json: @style.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /breweries/1 or /breweries/1.json
|
||||||
|
def destroy
|
||||||
|
@style.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to styles_url, notice: "Style was successfully destroyed." }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def style_params
|
||||||
|
params.require(:style).permit(:name, :description)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<%= link_to "users", users_path %>
|
<%= link_to "users", users_path %>
|
||||||
<%= link_to "clubs", beerclubs_path %>
|
<%= link_to "clubs", beerclubs_path %>
|
||||||
<%= link_to "places", places_path %>
|
<%= link_to "places", places_path %>
|
||||||
|
<%= link_to "styles", styles_path %>
|
||||||
|
|
|
|
||||||
<% if current_user.nil? %>
|
<% if current_user.nil? %>
|
||||||
<%= link_to "Sign up", new_user_path %>
|
<%= link_to "Sign up", new_user_path %>
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<%= form_with(model: style) do |form| %>
|
||||||
|
<div>
|
||||||
|
<%= form.label :name, style: "display: block" %>
|
||||||
|
<%= form.text_field :name %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :description, style: "display: block" %>
|
||||||
|
<%= form.text_field :description %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.submit %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
Name:
|
||||||
|
</strong>
|
||||||
|
<%= link_to style.name, style %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
Description:
|
||||||
|
</strong>
|
||||||
|
<%= style.description %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% Beer.where(style_id: style.id).each do |beer|%>
|
||||||
|
<li>
|
||||||
|
<%= link_to beer.name, beer %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<h1>Editing style</h1>
|
||||||
|
|
||||||
|
<%= render "form", style: @style %>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= link_to "Show this style", @style %> |
|
||||||
|
<%= link_to "Back to styles", styles_path %>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<h1>Styles</h1>
|
||||||
|
|
||||||
|
<%= notice %>
|
||||||
|
<% if @styles %>
|
||||||
|
<% @styles.each do |style|%>
|
||||||
|
<%= render style %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<%= notice %>
|
||||||
|
|
||||||
|
<%= render @style%>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= link_to "Edit this style", edit_style_path(@style) %> |
|
||||||
|
<%= link_to "Back to styles", styles_path %>
|
||||||
|
|
||||||
|
<%= button_to "Destroy this style", @style, method: :delete %>
|
||||||
|
</div>
|
||||||
@@ -3,6 +3,7 @@ Rails.application.routes.draw do
|
|||||||
resources :users
|
resources :users
|
||||||
resources :beers
|
resources :beers
|
||||||
resources :breweries
|
resources :breweries
|
||||||
|
resources :styles
|
||||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
||||||
|
|
||||||
# Defines the root path route ("/")
|
# Defines the root path route ("/")
|
||||||
|
|||||||
Reference in New Issue
Block a user