Postingan

Menampilkan postingan dari 2017

Rails select_month and select_year pre populate parameter

Hi all, I want to share to you how to pre populate parameter into your form. <%= select_month(params[:month].present? ? params[:month].to_i : Date.today.month, {}, {name: 'month'}) %> <%= select_year(params[:year].present? ? params[:year].to_i : Date.today.year, {start_year: 2017, end_year: Date.today.year}, {name: 'year'}) %> I hope this will help you.

Ruby invert hash

Hi all, This is how to invert hash manually. path_names = {:glass=>"gelas", :metals=>"", :other=>"lainnya", :papers=>"kertas", :plastics=>"plastik"} new_names = path_names.inject({}) { |h, (k, v)| h[v] = k; h } The result: {"gelas"=>:glass, "lainnya"=>:other, "kertas"=>:papers, "plastik"=>:plastics}