diff --git a/.idea/Chef.iml b/.idea/Chef.iml index 5fd8842..a3e3f08 100644 --- a/.idea/Chef.iml +++ b/.idea/Chef.iml @@ -59,6 +59,7 @@ + diff --git a/Gemfile b/Gemfile index 3ea5ff1..107854e 100644 --- a/Gemfile +++ b/Gemfile @@ -76,6 +76,8 @@ group :development do # Preview mail in the browser gem 'letter_opener', '~> 1.8' gem 'letter_opener_web', '~> 3.0' + + gem 'faker', '~> 3.4' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 618f514..bd4930e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,6 +118,8 @@ GEM warden (~> 1.2.3) drb (2.2.1) erubi (1.13.0) + faker (3.4.2) + i18n (>= 1.8.11, < 2) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.5) @@ -345,6 +347,7 @@ DEPENDENCIES cssbundling-rails debug devise (~> 4.9) + faker (~> 3.4) jbuilder jsbundling-rails letter_opener (~> 1.8) diff --git a/README.md b/README.md index 2d0c82d..a5901ef 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,34 @@ -# README +# Chef -This README would normally document whatever steps are necessary to get the -application up and running. +Chef is a simple toy project for learning and experimenting with Ruby on Rails. The end goal is to build an application for managing recipes. -Things you may want to cover: +## Getting Started -* Ruby version +Some parts of the application use JavaScript, specifically [daisyUI](https://daisyui.com/) as the component library, which needs to be built first. -* System dependencies +### Prerequisites -* Configuration +You'll need to install [Bun](https://bun.sh/docs/installation) by following the official installation guide for your platform. -* Database creation +### Setup -* Database initialization +Once Bun is installed, run the following commands to set up the frontend assets: -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... - -## Deploy to heroku -``` -git push heroku main +```bash +bun install +bun run build +bun run build:css ``` +Then, start the Rails server: -test database doesnt have any password - -http://localhost:3000/rails/mailers -http://localhost:3000/letter_opener - - - -Need to run -``` -bun install +```bash +bin/rails server ``` -``` -bun run build -``` +## Useful Links -``` -bun run build:css +The project uses [letter_opener](https://github.com/ryanb/letter_opener) to intercept emails in the development environment. You can access the intercepted emails at: -``` \ No newline at end of file +- [http://localhost:3000/rails/mailers](http://localhost:3000/rails/mailers) +- [http://localhost:3000/letter_opener](http://localhost:3000/letter_opener) \ No newline at end of file diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb new file mode 100644 index 0000000..fc3a1a8 --- /dev/null +++ b/app/controllers/recipes_controller.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class RecipesController < ApplicationController + before_action :set_recipe, only: [:edit, :destroy] + + def index + @recipes = Recipe.order(created_at: :desc) + end + + def new + @recipe = Recipe.new + end + + def edit + @recipe = Recipe.find(params[:id]) + end + + def create + @recipe = Recipe.new(recipe_params) + + if @recipe.save + redirect_to recipes_path + else + render :new, status: :unprocessable_entity + end + end + + def destroy + @recipe = Recipe.find(params[:id]) + @recipe.destroy + + redirect_to recipes_path + end + + private + + def recipe_params + params.require(:recipe).permit(:title, :description) + end + + def set_recipe + @recipe = Recipe.find(params[:id]) + end +end diff --git a/app/helpers/recipes_helper.rb b/app/helpers/recipes_helper.rb new file mode 100644 index 0000000..db49938 --- /dev/null +++ b/app/helpers/recipes_helper.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +module RecipesHelper +end diff --git a/app/models/recipe.rb b/app/models/recipe.rb new file mode 100644 index 0000000..a9d4169 --- /dev/null +++ b/app/models/recipe.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Recipe < ApplicationRecord +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index c066636..edd668f 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -7,6 +7,7 @@

<% if user_signed_in? %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2e32dce..45b557b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,6 +9,7 @@ <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <% if user_signed_in? %> @@ -20,14 +21,14 @@