From f27be0dce605412440b6317cd568610f01079f32 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 7 Apr 2021 20:44:30 -0400 Subject: PTU pokemon controller and view basic setup --- app/controllers/games/ptu/pokemon_controller.rb | 11 +++++++++ app/javascript/stylesheets/core.css | 3 ++- app/views/games/ptu/pokemon/_form.html.erb | 30 +++++++++++++++++++++++++ app/views/games/ptu/pokemon/edit.html.erb | 3 +++ app/views/games/ptu/pokemon/index.html.erb | 9 ++++++++ app/views/games/ptu/pokemon/new.html.erb | 29 +----------------------- app/views/games/ptu/pokemon/show.html.erb | 4 ++++ config/routes.rb | 2 +- 8 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 app/views/games/ptu/pokemon/_form.html.erb create mode 100644 app/views/games/ptu/pokemon/edit.html.erb create mode 100644 app/views/games/ptu/pokemon/index.html.erb diff --git a/app/controllers/games/ptu/pokemon_controller.rb b/app/controllers/games/ptu/pokemon_controller.rb index 485f03d..e5329a7 100644 --- a/app/controllers/games/ptu/pokemon_controller.rb +++ b/app/controllers/games/ptu/pokemon_controller.rb @@ -1,4 +1,8 @@ class Games::Ptu::PokemonController < ApplicationController + def index + @pokemons = PtuPokemon.all + end + def show @pokemon = PtuPokemon.find(params[:id]) end @@ -18,6 +22,13 @@ class Games::Ptu::PokemonController < ApplicationController end end + def edit + @pokemon = PtuPokemon.find(params[:id]) + end + + def update + end + private def pokemon_params params.require(:ptu_pokemon).permit(:name, :base_hp, :base_atk, :base_def, :base_spatk, :base_spdef, diff --git a/app/javascript/stylesheets/core.css b/app/javascript/stylesheets/core.css index 15b234b..ec06839 100644 --- a/app/javascript/stylesheets/core.css +++ b/app/javascript/stylesheets/core.css @@ -10,7 +10,8 @@ p { } label { - @apply mb-2; + @apply mt-2; + display: block; } input { diff --git a/app/views/games/ptu/pokemon/_form.html.erb b/app/views/games/ptu/pokemon/_form.html.erb new file mode 100644 index 0000000..aeb4dea --- /dev/null +++ b/app/views/games/ptu/pokemon/_form.html.erb @@ -0,0 +1,30 @@ +<%= form_with model: @pokemon, + url: @pokemon.new_record? ? games_ptu_pokemon_index_path : games_ptu_pokemon_path do |f| %> + <%= f.label :name %> + <%= f.text_field :name, required: true %> + + <%= f.label :base_hp, "Base HP" %> + <%= f.number_field :base_hp, value: @pokemon.base_hp, min: 1, required: true %> + + <%= f.label :base_atk, "Base ATK" %> + <%= f.number_field :base_atk, value: @pokemon.base_atk, min: 1, required: true %> + + <%= f.label :base_def, "Base DEF" %> + <%= f.number_field :base_def, value: @pokemon.base_def, min: 1, required: true %> + + <%= f.label :base_spatk, "Base SPATK" %> + <%= f.number_field :base_spatk, value: @pokemon.base_spatk, min: 1, required: true %> + + <%= f.label :base_spdef, "Base SPDEF" %> + <%= f.number_field :base_spdef, value: @pokemon.base_spdef, min: 1, required: true %> + + <%= f.label :base_speed, "Base SPEED" %> + <%= f.number_field :base_speed, value: @pokemon.base_speed, min: 1, required: true %> + + <%= f.label :male_chance, "Male Chance" %> + <%= f.number_field :male_chance, value: @pokemon.male_chance, min: 0, step: 0.01 %> % + + <%= f.submit "Save", class: "block mt-4" %> +<% end %> +<%= button_to "Cancel", @pokemon.new_record? ? games_ptu_pokemon_index_path : games_ptu_pokemon_path(@pokemon), + method: :get, class: "mt-4" %> diff --git a/app/views/games/ptu/pokemon/edit.html.erb b/app/views/games/ptu/pokemon/edit.html.erb new file mode 100644 index 0000000..684ee4d --- /dev/null +++ b/app/views/games/ptu/pokemon/edit.html.erb @@ -0,0 +1,3 @@ +

New Pokemon - <%= @pokemon.name %>

+ +<%= render "form" %> diff --git a/app/views/games/ptu/pokemon/index.html.erb b/app/views/games/ptu/pokemon/index.html.erb new file mode 100644 index 0000000..a1d7443 --- /dev/null +++ b/app/views/games/ptu/pokemon/index.html.erb @@ -0,0 +1,9 @@ +

Pokemon

+ +
<%= link_to "New", new_games_ptu_pokemon_path %>
+ + diff --git a/app/views/games/ptu/pokemon/new.html.erb b/app/views/games/ptu/pokemon/new.html.erb index 7ba0426..404bd47 100644 --- a/app/views/games/ptu/pokemon/new.html.erb +++ b/app/views/games/ptu/pokemon/new.html.erb @@ -1,30 +1,3 @@

New Pokemon

-<%= form_with model: @pokemon, url: games_ptu_pokemon_index_path do |f| %> - <%= f.label :name %> - <%= f.text_field :name, required: true %> - - <%= f.label :base_hp, "Base HP" %> - <%= f.number_field :base_hp, min: 1, required: true %> - - <%= f.label :base_atk, "Base ATK" %> - <%= f.number_field :base_atk, min: 1, required: true %> - - <%= f.label :base_def, "Base DEF" %> - <%= f.number_field :base_def, min: 1, required: true %> - - <%= f.label :base_spatk, "Base SPATK" %> - <%= f.number_field :base_spatk, min: 1, required: true %> - - <%= f.label :base_spdef, "Base SPDEF" %> - <%= f.number_field :base_spdef, min: 1, required: true %> - - <%= f.label :base_speed, "Base SPEED" %> - <%= f.number_field :base_speed, min: 1, required: true %> - - <%= f.label :male_chance, "Male Chance" %> - <%= f.number_field :male_chance, min: 0, step: 0.01 %> % - - <%= f.submit "Save" %> - -<% end %> +<%= render "form" %> diff --git a/app/views/games/ptu/pokemon/show.html.erb b/app/views/games/ptu/pokemon/show.html.erb index e7b80ce..c4454cd 100644 --- a/app/views/games/ptu/pokemon/show.html.erb +++ b/app/views/games/ptu/pokemon/show.html.erb @@ -1,5 +1,9 @@ +
<%= link_to "Back", games_ptu_pokemon_index_path %>
+

<%= @pokemon.name %>

+
<%= link_to "Edit", edit_games_ptu_pokemon_path(@pokemon) %>
+ diff --git a/config/routes.rb b/config/routes.rb index 45d70ea..e54ecf2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ Rails.application.routes.draw do namespace :games do namespace :ptu do - resources :pokemon, only: [:show, :new, :create] + resources :pokemon end end end -- cgit v1.2.3
Base HP