我正在尝试显示一个页面,以显示当前用户的所有产品.因此,我在产品视图下创建了一个新页面showall.html.erb.
我做了以下事情:
的ProductsController
def showall
@products = current_user.products
end
Run Code Online (Sandbox Code Playgroud)
路线
resources :products do
get :showall
end
Run Code Online (Sandbox Code Playgroud)
我知道由于URL模式的嵌套资源
/products/:product_id/showall(.:format)
Run Code Online (Sandbox Code Playgroud)
我如何实际摆脱product_id部分以实现/ products/showall有一个特殊页面来呈现当前用户的所有产品.
我的哈希看起来如下.我希望输出是相同的哈希形式,但根据价格排列哈希.
{
1=>{
"name"=>"Mark",
"date"=>"27/08/2015",
"bed"=>"3",
"furnish"=>"Fully",
"size"=>"10",
"price"=>790000
},
2=>{
"name"=>"Mark",
"date"=>"27/08/2015",
"bed"=>"3",
"furnish"=>"Fully",
"size"=>"10",
"price"=>720000
},
3=>{
"name"=>"Mark",
"date"=>"27/08/2015",
"bed"=>"3",
"furnish"=>"Fully",
"size"=>"10",
"price"=>750000
},
4=>{
"name"=>"Mark",
"date"=>"27/08/2015",
"bed"=>"3",
"furnish"=>"Fully",
"size"=>"10",
"price"=>710000
}
}
Run Code Online (Sandbox Code Playgroud)
我读过如何按数值对Ruby Hash进行排序?但它只是一个嵌套的哈希.对我如何实现这一目标完全无能为力.如果你们中的任何一个愿意帮助我,将不胜感激.