-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca09694
commit c67f67e
Showing
23 changed files
with
252 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ColorsController < ApplicationController | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class PalettesController < ApplicationController | ||
http_basic_authenticate_with name: "dhh", password: "secret", except: [ :index, :show ] | ||
|
||
def index | ||
@palettes = Palette.all | ||
end | ||
|
||
def show | ||
@palette = Palette.find(params[:id]) | ||
end | ||
|
||
def new | ||
@palette = Palette.new | ||
end | ||
|
||
def create | ||
@palette = Palette.new(palette_params) | ||
|
||
if @palette.save | ||
redirect_to @palette | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def edit | ||
@palette = Palette.find(params[:id]) | ||
end | ||
|
||
def update | ||
@palette = Palette.find(params[:id]) | ||
|
||
if @palette.update(palette_params) | ||
redirect_to @palette | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@palette = Palette.find(params[:id]) | ||
@palette.destroy | ||
|
||
redirect_to root_path, status: :see_other | ||
end | ||
|
||
private | ||
def palette_params | ||
params.require(:palette).permit(:name, :is_color_history, :is_favorite, :is_locked) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ColorsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PalettesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Color < ApplicationRecord | ||
belongs_to :palette | ||
|
||
# serialize :color_order, Array | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Palette < ApplicationRecord | ||
has_many :colors | ||
|
||
validates :name, presence: true | ||
validates :is_color_history, inclusion: { in: [ true, false ] } | ||
validates :is_favorite, inclusion: { in: [ true, false ] } | ||
validates :is_locked, inclusion: { in: [ true, false ] } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%= form_with model: @palette do |form| %> | ||
<div> | ||
<%= form.label :name %><br> | ||
<%= form.text_field :name %> | ||
<% @palette.errors.full_messages_for(:name).each do |message| %> | ||
<div><%= message %></div> | ||
<% end %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :is_favorite %><br> | ||
<%= form.collection_radio_buttons :is_favorite, [[true, 'Yes'], [false, 'No']], :first, :last %> | ||
<% @palette.errors.full_messages_for(:is_favorite).each do |message| %> | ||
<div><%= message %></div> | ||
<% end %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1>Edit Palette</h1> | ||
|
||
<%= render "form", palette: @palette %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h1>Palettes</h1> | ||
|
||
<ul> | ||
<% @palettes.each do |palette| %> | ||
<li> | ||
<%= link_to palette.name, palette %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
|
||
<%= link_to "New Palette", new_palette_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1>New Palette</h1> | ||
|
||
<%= render "form", palette: @palette %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<h1><%= @palette.name %></h1> | ||
|
||
<p><%= @palette.is_favorite %></p> | ||
|
||
<%= link_to "Edit", edit_palette_path(@palette) %> | ||
<%= link_to "Delete", palette_path(@palette), data: { | ||
turbo_method: :delete, | ||
turbo_confirm: "Are you sure?" | ||
} %> | ||
|
||
|
||
<h2>Colors</h2> | ||
<% @palette.colors.each do |color| %> | ||
<p> | ||
<%= color.name %> | ||
</p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreatePalettes < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :palettes do |t| | ||
t.string :name | ||
t.integer :index | ||
t.boolean :is_color_history, default: false | ||
t.boolean :is_favorite, default: false | ||
t.boolean :is_locked, default: false | ||
t.integer :selected_color_index | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateColors < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :colors do |t| | ||
t.string :name | ||
t.references :palette, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class AddRgbaToColors < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :colors, :r, :integer | ||
add_column :colors, :g, :integer | ||
add_column :colors, :b, :integer | ||
add_column :colors, :a, :integer | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20240909201548_add_color_order_array_to_palettes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddColorOrderArrayToPalettes < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :palettes, :color_order, :json, default: [] | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class ColorsControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "test_helper" | ||
|
||
class PalettesControllerTest < ActionDispatch::IntegrationTest | ||
test "should get index" do | ||
get palettes_index_url | ||
assert_response :success | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
name: MyString | ||
palette: one | ||
|
||
two: | ||
name: MyString | ||
palette: two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
name: MyString | ||
|
||
two: | ||
name: MyString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class ColorTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class PaletteTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |