Skip to content

Commit

Permalink
Better NG Words handling
Browse files Browse the repository at this point in the history
  • Loading branch information
morygonzalez committed May 4, 2021
1 parent da02ff3 commit 715aa9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions public/plugin/lokka-ng_words/lib/lokka/ng_words.rb
Expand Up @@ -24,7 +24,7 @@ def self.registered(app)

app.put '/admin/plugins/ng_words' do
login_required
Option.ng_words = params[:ng_words][:ng_words]
Option.ng_words = ng_words_params
if Option.ng_words
flash[:notice] = t('ng_words.updated')
redirect to('/admin/plugins/ng_words')
Expand All @@ -46,7 +46,11 @@ def spam?
end

def ng_words
Option.ng_words
Option.ng_words&.split(',')&.map(&:strip)
end

def ng_words_params
params[:ng_words].values.delete_if {|item| item.blank? }.join(', ')
end
end
end
4 changes: 3 additions & 1 deletion public/plugin/lokka-ng_words/views/index.haml
Expand Up @@ -5,7 +5,9 @@
.field
%label{ for: :ng_words_key }= t('ng_words.ng_words')
%br
%input{ type: :text, id: :ng_words, name: 'ng_words[ng_words]', value: @ng_words }
- @ng_words.each_with_index do |word, index|
%input{ type: :text, name: "ng_words[ng_words_#{index}]", value: word }
%input{ type: :text, name: "ng_words[ng_words_#{@ng_words.length}]", placeholder: I18n.t('new') }
%br
.field
%p
Expand Down

0 comments on commit 715aa9b

Please sign in to comment.