diff --git a/Gemfile b/Gemfile index 8bd546f..2b116f7 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ git_source(:github) do |repo_name| end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.1.6' +gem 'rails', '~> 5.2' # Use sqlite3 as the database for Active Record gem 'sqlite3', '1.5' # Use Puma as the app server @@ -31,6 +31,8 @@ gem 'jbuilder', '~> 2.5' # Use ActiveModel has_secure_password gem 'bcrypt', '~> 3.1.7' +gem 'bootsnap', require: false + # Use Capistrano for deployment # gem 'capistrano-rails', group: :development diff --git a/Gemfile.lock b/Gemfile.lock index 2f28a03..dc73f4c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,47 +1,53 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.1.7) - actionpack (= 5.1.7) + actioncable (5.2.8.1) + actionpack (= 5.2.8.1) nio4r (~> 2.0) - websocket-driver (~> 0.6.1) - actionmailer (5.1.7) - actionpack (= 5.1.7) - actionview (= 5.1.7) - activejob (= 5.1.7) + websocket-driver (>= 0.6.1) + actionmailer (5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.7) - actionview (= 5.1.7) - activesupport (= 5.1.7) - rack (~> 2.0) + actionpack (5.2.8.1) + actionview (= 5.2.8.1) + activesupport (= 5.2.8.1) + rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.7) - activesupport (= 5.1.7) + actionview (5.2.8.1) + activesupport (= 5.2.8.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.7) - activesupport (= 5.1.7) + activejob (5.2.8.1) + activesupport (= 5.2.8.1) globalid (>= 0.3.6) - activemodel (5.1.7) - activesupport (= 5.1.7) - activerecord (5.1.7) - activemodel (= 5.1.7) - activesupport (= 5.1.7) - arel (~> 8.0) - activesupport (5.1.7) + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activerecord (5.2.8.1) + activemodel (= 5.2.8.1) + activesupport (= 5.2.8.1) + arel (>= 9.0) + activestorage (5.2.8.1) + actionpack (= 5.2.8.1) + activerecord (= 5.2.8.1) + marcel (~> 1.0.0) + activesupport (5.2.8.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - arel (8.0.0) + arel (9.0.0) base64 (0.2.0) bcrypt (3.1.20) bindex (0.8.1) + bootsnap (1.18.4) + msgpack (~> 1.2) builder (3.3.0) byebug (11.1.3) coffee-rails (4.2.2) @@ -56,7 +62,7 @@ GEM date (3.3.4) erubi (1.13.0) execjs (2.9.1) - ffi (1.17.0-arm64-darwin) + ffi (1.17.0) globalid (1.1.0) activesupport (>= 5.0) i18n (1.14.5) @@ -79,9 +85,12 @@ GEM net-imap net-pop net-smtp + marcel (1.0.4) method_source (1.1.0) mini_mime (1.1.5) - minitest (5.24.1) + mini_portile2 (2.8.7) + minitest (5.25.1) + msgpack (1.7.2) net-imap (0.4.14) date net-protocol @@ -92,7 +101,8 @@ GEM net-smtp (0.5.0) net-protocol nio4r (2.7.3) - nokogiri (1.15.6-arm64-darwin) + nokogiri (1.15.6) + mini_portile2 (~> 2.8.2) racc (~> 1.4) puma (6.4.2) nio4r (~> 2.0) @@ -100,17 +110,18 @@ GEM rack (2.2.9) rack-test (2.1.0) rack (>= 1.3) - rails (5.1.7) - actioncable (= 5.1.7) - actionmailer (= 5.1.7) - actionpack (= 5.1.7) - actionview (= 5.1.7) - activejob (= 5.1.7) - activemodel (= 5.1.7) - activerecord (= 5.1.7) - activesupport (= 5.1.7) + rails (5.2.8.1) + actioncable (= 5.2.8.1) + actionmailer (= 5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + activemodel (= 5.2.8.1) + activerecord (= 5.2.8.1) + activestorage (= 5.2.8.1) + activesupport (= 5.2.8.1) bundler (>= 1.3.0) - railties (= 5.1.7) + railties (= 5.2.8.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) @@ -119,12 +130,12 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (5.1.7) - actionpack (= 5.1.7) - activesupport (= 5.1.7) + railties (5.2.8.1) + actionpack (= 5.2.8.1) + activesupport (= 5.2.8.1) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + thor (>= 0.19.0, < 2.0) rake (13.2.1) rb-fsevent (0.11.2) rb-inotify (0.11.1) @@ -134,8 +145,8 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) + sass-rails (5.1.0) + railties (>= 5.2.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) @@ -148,11 +159,12 @@ GEM base64 concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.5.0-arm64-darwin) + sqlite3 (1.5.0) + mini_portile2 (~> 2.8.0) thor (1.3.1) thread_safe (0.3.6) tilt (2.4.0) @@ -169,22 +181,23 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.6.5) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) PLATFORMS - arm64-darwin-23 + ruby DEPENDENCIES bcrypt (~> 3.1.7) + bootsnap byebug coffee-rails (~> 4.2) jbuilder (~> 2.5) jquery-rails listen (~> 3.0.5) puma - rails (~> 5.1.6) + rails (~> 5.2) sass-rails (~> 5.0) spring spring-watcher-listen (~> 2.0.0) @@ -195,4 +208,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 2.4.22 + 2.1.4 diff --git a/app/controllers/house_plants_controller.rb b/app/controllers/house_plants_controller.rb index 8ab5e61..d481063 100644 --- a/app/controllers/house_plants_controller.rb +++ b/app/controllers/house_plants_controller.rb @@ -2,4 +2,28 @@ class HousePlantsController < ApplicationController def index @house_plants = HousePlant.all end + + def show + @house_plant = HousePlant.find(params[:id]) + end + + def new + @house_plant = HousePlant.new + @rooms = Room.all + @house_plant.room_id = params[:room_id] if params[:room_id] + end + + def create + @house_plant = HousePlant.new(house_plant_params) + @rooms = Room.all + if @house_plant.save + redirect_to house_plant_path(@house_plant) + else + render :new + end + end + + def house_plant_params + params.require(:house_plant).permit(:plant_type, :height, :room_id) + end end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index efb8527..7712be9 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -2,4 +2,8 @@ class RoomsController < ApplicationController def index @rooms = Room.all end + + def show + @room = Room.find(params[:id]) + end end diff --git a/app/models/house_plant.rb b/app/models/house_plant.rb index b98a562..4a8ff3d 100644 --- a/app/models/house_plant.rb +++ b/app/models/house_plant.rb @@ -1,3 +1,10 @@ class HousePlant < ApplicationRecord + belongs_to :room + validates :plant_type, :height, :room, presence: true + validates :height, numericality: { greater_than_or_equal_to: 1 } + + def room_name + room.name + end end diff --git a/app/models/room.rb b/app/models/room.rb index cc4a0b5..bb18b3a 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -1,3 +1,3 @@ class Room < ApplicationRecord - + has_many :house_plants end diff --git a/app/views/house_plants/index.html.erb b/app/views/house_plants/index.html.erb index e65cdb2..164f0c8 100644 --- a/app/views/house_plants/index.html.erb +++ b/app/views/house_plants/index.html.erb @@ -1,7 +1,9 @@
<%= @house_plant.height %> inches
+ +<%= @room.occupancy %> people
+ +