Commit 5e584ee6264962cc60d9074c33141a28b4100607

Authored by Nihad Abbasov
1 parent de4e8599

refactor lifetime_select helper

app/helpers/snippets_helper.rb
1 1 module SnippetsHelper
2   - def snippet_lifetime_select_options
  2 + def lifetime_select_options
3 3 options = [
4 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 9 options_for_select(options)
10 10 end
... ...
app/views/snippets/_form.html.haml
... ... @@ -14,7 +14,7 @@
14 14 %td= f.text_field :file_name, :placeholder => "example.rb"
15 15 %tr
16 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 18 %tr
19 19 %td{:colspan => 2}
20 20 = f.label :content, "Code"
... ...