Commit 5e584ee6264962cc60d9074c33141a28b4100607

Authored by Nihad Abbasov
1 parent de4e8599

refactor lifetime_select helper

app/helpers/snippets_helper.rb
1 module SnippetsHelper 1 module SnippetsHelper
2 - def snippet_lifetime_select_options 2 + def lifetime_select_options
3 options = [ 3 options = [
4 ['forever', nil], 4 ['forever', nil],
5 - ['1 day', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.day],  
6 - ['1 week', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.week],  
7 - ['1 month', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.month] 5 + ['1 day', "#{Date.current + 1.day}"],
  6 + ['1 week', "#{Date.current + 1.week}"],
  7 + ['1 month', "#{Date.current + 1.month}"]
8 ] 8 ]
9 options_for_select(options) 9 options_for_select(options)
10 end 10 end
app/views/snippets/_form.html.haml
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 %td= f.text_field :file_name, :placeholder => "example.rb" 14 %td= f.text_field :file_name, :placeholder => "example.rb"
15 %tr 15 %tr
16 %td= f.label "Lifetime" 16 %td= f.label "Lifetime"
17 - %td= f.select :expires_at, snippet_lifetime_select_options 17 + %td= f.select :expires_at, lifetime_select_options
18 %tr 18 %tr
19 %td{:colspan => 2} 19 %td{:colspan => 2}
20 = f.label :content, "Code" 20 = f.label :content, "Code"