diff --git a/app/controllers/thaalis_controller.rb b/app/controllers/thaalis_controller.rb
index c1340273..9d67cf2a 100644
--- a/app/controllers/thaalis_controller.rb
+++ b/app/controllers/thaalis_controller.rb
@@ -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
diff --git a/app/views/thaalis/_form.html.erb b/app/views/thaalis/_form.html.erb
new file mode 100644
index 00000000..45b2cc44
--- /dev/null
+++ b/app/views/thaalis/_form.html.erb
@@ -0,0 +1,11 @@
+
+ <%= 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 %>
+
diff --git a/app/views/thaalis/edit.html.erb b/app/views/thaalis/edit.html.erb
index ba13ad48..55b6c767 100644
--- a/app/views/thaalis/edit.html.erb
+++ b/app/views/thaalis/edit.html.erb
@@ -2,14 +2,4 @@
Edit Thaali
-
- <%= 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 %>
-
+<%= render "form", path: thaali_path %>
diff --git a/app/views/thaalis/new.html.erb b/app/views/thaalis/new.html.erb
index 32519830..80878996 100644
--- a/app/views/thaalis/new.html.erb
+++ b/app/views/thaalis/new.html.erb
@@ -2,14 +2,4 @@
New Thaali
-
- <%= 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 %>
-
+<%= render "form", path: sabeel_thaalis_path %>