Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/Chef.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -345,6 +347,7 @@ DEPENDENCIES
cssbundling-rails
debug
devise (~> 4.9)
faker (~> 3.4)
jbuilder
jsbundling-rails
letter_opener (~> 1.8)
Expand Down
55 changes: 19 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

```
- [http://localhost:3000/rails/mailers](http://localhost:3000/rails/mailers)
- [http://localhost:3000/letter_opener](http://localhost:3000/letter_opener)
44 changes: 44 additions & 0 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions app/helpers/recipes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

module RecipesHelper
end
4 changes: 4 additions & 0 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Recipe < ApplicationRecord
end
1 change: 1 addition & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</p>
<% if user_signed_in? %>
<ul class="menu bg-base-200 rounded-box">
<li><%= link_to "Recipes", recipes_path %></li>
<li><%= link_to "Profile", edit_user_registration_path %></li>
<li><%= link_to "Sign Out", destroy_user_session_path, data: { turbo_method: :delete, turbo_confirm: 'Are you sure?'}%></li>
</ul>
Expand Down
5 changes: 3 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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' %>
</head>
<body data-controller="navigation">
<% if user_signed_in? %>
Expand All @@ -20,14 +21,14 @@

<div class="hidden md:block">
<!-- Content for desktop -->
<div class="bg-state-200 sticky top-0 p-2">
<div class="bg-state-200 sticky top-0 p-2 overflow-hidden">
<%= render "shared/header" %>
</div>
<div class="flex relative">
<div id="nav-container" data-navigation-target="nav" class="sticky h-[calc(100vh-64px)] px-2 transform transition-transform duration-300 ease-in-out hidden" style="top: 4rem">
<%= render "shared/navigation" %>
</div>
<div id="main-container" data-navigation-target="main" class="w-full px-2 min-h-16 transform transition-transform duration-300 ease-in-out">
<div id="main-container" data-navigation-target="main" class="container center mx-auto transform transition-transform duration-300 ease-in-out">
<%= yield %>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions app/views/recipes/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<% @recipe.title %>
</div>
<div>
<% @recipe.description %>
</div>
38 changes: 38 additions & 0 deletions app/views/recipes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="mt-5 flex flex-row justify-between items-center">
<div>
<h2 class="text-2xl pb-1 font-semibold ">Recipes</h2>
<p class="font-light">A list of all the users in your account including their name, title, email and role.</p>
</div>
<div>
<%= link_to "Add", new_recipe_path, class: "btn btn-accent btn-sm" %>
</div>
</div>
<div class="mt-5 h-96 bg-base-300 border-separate overflow-clip flex flex-col card md:shadow-xl">
<table class="w-full table-fixed">
<thead class="sticky top-0">
<tr>
<th class="p-2">Title</th>
<th class="p-2">Description</th>
</tr>
</thead>
</table>
<div class="flex-1 overflow-y-auto">
<table class="w-full table-fixed">
<tbody>
<% @recipes.each do |recipe| %>
<tr class="cursor-pointer space-x-2 hover:bg-base-200">
<td class="p-2"><%= recipe.title %></td>
<td class="p-2"><%= recipe.description %></td>
<td class="p-2 flex justify-end space-x-2">
<%= link_to "Edit", edit_recipe_path(recipe), class: "btn btn-primary btn-sm" %>
<%== link_to "Delete", recipe_path(recipe), data: {
turbo_method: :delete,
turbo_confirm: "Are you sure?"
} , class: 'btn btn-sm btn-error' %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
14 changes: 14 additions & 0 deletions app/views/recipes/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="flex justify-center items-center min-h-screen">
<%= form_with model: @recipe do |f| %>
<div class="field">
<%= f.text_field :title, autofocus: true, autocomplete: "title", placeholder: "Title", class: "input input-bordered w-full max-w-xs mb-3" %>
</div>

<div class="field">
<%= f.text_field :description, autofocus: true, autocomplete: "description", placeholder: "Description", class: "input input-bordered w-full max-w-xs mb-3" %>
</div>
<div class="mt-2 w-full">
<%= f.submit "Add recipe", class: "btn btn-primary"%>
</div>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</button>
</div>
<div class="flex-1">
<a class="btn btn-ghost text-accent">Chef</a>
<%= link_to "Chef", root_path, class: "btn btn-ghost text-accent"%>
</div>
<div class="flex-none">
<button class="btn rounded-box btn-ghost">
Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
# Can be used by load balancers and uptime monitors to verify that the app is live.
get 'up' => 'rails/health#show', :as => :rails_health_check

# Defines the root path route ("/")
# root "posts#index"
resources :recipes
end
2 changes: 1 addition & 1 deletion config/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ module.exports = {
},
},
plugins: [
require("daisyui"),
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
require("daisyui"),
],
daisyui: {
themes: ["light", "dark", "cupcake"],
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20240905222849_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class CreateRecipes < ActiveRecord::Migration[7.1]
def change
create_table :recipes do |t|
t.string :title
t.text :description

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/tasks/recipes.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

namespace :recipes do
desc 'Seed recipes'
task seed: :environment do
100.times do
Recipe.create!(title: Faker::Food.dish, description: Faker::Food.description)
end
p 'Done seeding recipes'
end
end
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"dependencies": {
"daisyui": "^4.12.10",
"@hotwired/stimulus": "^3.2.2",
"@hotwired/turbo-rails": "^8.0.5",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
"autoprefixer": "^10.4.20",
"daisyui": "^4.12.10",
"postcss": "^8.4.41",
"tailwindcss": "^3.4.9"
},
Expand Down
9 changes: 9 additions & 0 deletions test/controllers/recipes_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'test_helper'

class RecipesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
9 changes: 9 additions & 0 deletions test/fixtures/recipes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
title: MyString
description: MyString

two:
title: MyString
description: MyString
9 changes: 9 additions & 0 deletions test/models/recipe_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'test_helper'

class RecipeTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end