这是我第一次在这里发帖。
我在html中有九个按钮传递给ruby on rails。
这是我要循环的参数:
Button.new(:title => params[:button_title_1], :order => 1, :icon_url => params[:button_icon_1], :navigation_id => @navigation.id,
:next_navigation => params[:selected_navigation_1].to_i, :next_page => params[:selected_page_1].to_i)
我想将数字1转换为i并将其置于循环下方:
@buttonNumber.each do |i|
end
请帮忙!谢谢!
答案 0 :(得分:0)
@buttonNumber.each do |i|
Button.new(:title => params["button_title_#{i}".to_sym],
:order => 1,
:icon_url => params["button_icon_#{i}".to_sym],
:navigation_id => @navigation.id,
:next_navigation => params["selected_navigation_#{i}".to_sym].to_i,
:next_page => params["selected_page_#{i}".to_sym].to_i)
end
“to_sym”是可选的,因为params集合是HashWithIndifferentAccess,我把它用于更好地理解其他情况。