ruby-dev-log

collect_with_index

require 'enumerator'
['a', 'b', 'c'].enum_for(:each_with_index).collect do |item, index| 
  "#{index}: #{item}" 
end

permit-array-rails-strong-parameters

  • which version happened rails 4+

  • why: The most standard use case for permit is to pass it a collection of :symbols. These keys must represent scalar values (string, number, that sort) only.

  • how to solve

params[:luchador][:wins] ||= []
params.require(:luchador).permit(:favorite_move, :weight, wins: [])