@@ -4,8 +4,9 @@ class ColorThemes::ShowView < ApplicationView
4
4
include Phlex ::Rails ::Helpers ::FormWith
5
5
include Phlex ::Rails ::Helpers ::LinkTo
6
6
7
- def initialize ( color_scale :, curated_color_scales : [ ] , selected : false )
8
- @color_scale = color_scale
7
+ def initialize ( color_theme :, curated_color_scales : [ ] , selected : false )
8
+ @color_theme = color_theme
9
+ @color_scale = color_theme . color_scale
9
10
@curated_color_scales = curated_color_scales
10
11
@selected = selected
11
12
end
@@ -17,9 +18,10 @@ def view_template
17
18
18
19
p { "You can preview and save your desired color theme for this site. We have curated some options for you below." }
19
20
20
- form_with ( url : url_for , method : :get ) do |f |
21
+ form_with ( model : @color_theme , url : url_for , method : :get ) do |f |
21
22
fieldset ( class : "flex items-center" ) do
22
- f . select :id ,
23
+ f . select (
24
+ :color_scale_id ,
23
25
@curated_color_scales . map { |cs | [ cs . display_name , cs . id ] } ,
24
26
{
25
27
prompt : "Pick one!" ,
@@ -29,9 +31,10 @@ def view_template
29
31
# https://stackoverflow.com/questions/68624668/how-can-i-submit-a-form-on-input-change-with-turbo-streams
30
32
onchange : "this.form.requestSubmit()" ,
31
33
class : "mr-2 bg-gray-50 border border-gray-300 text-small rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
34
+ )
32
35
33
36
span ( class : "mr-2 text-small" ) { "OR" }
34
- link_to "I feel lucky!" , url_for ( id : @curated_color_scales . sample . id ) , class : "button primary mr-2"
37
+ link_to "I feel lucky!" , url_for ( color_theme : { color_scale_id : @curated_color_scales . sample . id } ) , class : "button primary mr-2"
35
38
if @selected
36
39
span ( class : "mr-2 text-small" ) { unsafe_raw "•" }
37
40
link_to "Reset to default" , url_for , class : "button secondary"
0 commit comments