Skip to content

Commit

Permalink
refactor thaali form
Browse files Browse the repository at this point in the history
  • Loading branch information
JuzerShakir committed Jan 2, 2024
1 parent e7dfb20 commit b646eb2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/controllers/thaalis_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def show

def new
@thaali = @sabeel.thaalis.new
@thaali.year = CURR_YR

if @sabeel.took_thaali?
took_thaali = @thaalis.where(year: PREV_YR).first
@thaali.number = took_thaali[:number]
@thaali.size = took_thaali[:size]
@thaali.attributes = took_thaali.slice(:number, :size)
else
# uncheck the default option
@thaali.size = nil
Expand Down
11 changes: 11 additions & 0 deletions app/views/thaalis/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="container col-xxl-6 col-xl-7 col-lg-8 col-md-11 col-sm-10 pt-4 p-5 bg-white bg-opacity-50 shadow-lg border border-2 border-success-subtle rounded-4 mb-5">
<%= simple_form_for @thaali, url: path do |f| %>
<%= f.error_notification %>

<%= f.input :year, disabled: true %>
<%= f.input :number %>
<%= f.input :size, collection: collection_of(Thaali.sizes), as: :radio_buttons %>
<%= f.input :total, disabled: action_name == "edit" %>
<%= f.button :submit, action_name: %>
<% end %>
</div>
12 changes: 1 addition & 11 deletions app/views/thaalis/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,4 @@

<h2 class="heading mb-3">Edit Thaali</h2>

<div class="container col-xxl-6 col-xl-7 col-lg-8 col-md-11 col-sm-10 pt-4 p-5 bg-white bg-opacity-50 shadow-lg border border-2 border-success-subtle rounded-4 mb-5">
<%= simple_form_for @thaali, url: thaali_path do |f| %>
<%= f.error_notification %>

<%= f.input :year, disabled: true, input_html: {value: @thaali.year} %>
<%= f.input :number %>
<%= f.input :size, collection: collection_of(Thaali.sizes), as: :radio_buttons %>
<%= f.input :total, disabled: true %>
<%= f.button :submit, action_name: %>
<% end %>
</div>
<%= render "form", path: thaali_path %>
12 changes: 1 addition & 11 deletions app/views/thaalis/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,4 @@

<h2 class="heading mb-3">New Thaali</h2>

<div class="container col-xxl-6 col-xl-7 col-lg-8 col-md-11 col-sm-10 pt-4 p-5 bg-white bg-opacity-50 shadow-lg border border-2 border-success-subtle rounded-4 mb-5">
<%= simple_form_for @thaali, url: sabeel_thaalis_path do |f| %>
<%= f.error_notification %>

<%= f.input :year, disabled: true, input_html: {value: CURR_YR} %>
<%= f.input :number %>
<%= f.input :size, collection: collection_of(Thaali.sizes), as: :radio_buttons %>
<%= f.input :total %>
<%= f.button :submit, action_name: %>
<% end %>
</div>
<%= render "form", path: sabeel_thaalis_path %>

0 comments on commit b646eb2

Please sign in to comment.